Skip to content

fix: newly added Block Grid area blocks never render a preview (#322) [v5] - #334

Open
rickbutterfield wants to merge 1 commit into
v5/devfrom
claude/issue-322-v5-fix
Open

fix: newly added Block Grid area blocks never render a preview (#322) [v5]#334
rickbutterfield wants to merge 1 commit into
v5/devfrom
claude/issue-322-v5-fix

Conversation

@rickbutterfield

Copy link
Copy Markdown
Owner

Summary

Backports the v6 fix (#333) for #322 to the v5 line — a newly added, unsaved Block Grid block with areas never renders a preview.

This is very likely the cause of the two follow-up reports on #322: one user hit the bug on 5.5.0/Umbraco 17.6.0, and confirmed downgrading to 5.4.1 fixed it. v5/main (5.5.0) still has the defer guard described below; it predates 5.4.1 or was reintroduced by the #293 fix and has never been corrected on this line.

Root cause: Umbraco's UmbBlockGridEntryContext derives layoutAreas as layout?.areas. A brand-new block is created with an empty partialLayoutEntry: {}, so its layout entry has no areas key at all — layoutAreas stays undefined until content is added into an area or the document is saved and reloaded.

The #293 fix added a guard that deferred the initial preview render whenever a block had configured areas but layoutAreas hadn't arrived yet, to avoid a transient incomplete render. For brand-new blocks that guard never releases, so the preview stays permanently blank and the area's "Add new Layout" button (part of the server-rendered markup) is unreachable.

Fix: Removed the defer/early-return in #observeBlockPropertyValue, identical to the v6 fix. #filterLayouts() already defaults each area's items to [] when layoutAreas is missing, so rendering immediately is safe and correct for new blocks. The existing re-render trigger in observeBlockValue (fired when layoutAreas transitions from absent to present) is untouched, so the #293 fix for saved blocks with a content/settings-vs-layoutAreas race is preserved.

  • src/Umbraco.Community.BlockPreview.UI/src/blockEditor/block-grid-preview.custom-view.element.ts — remove the defer guard
  • wwwroot/App_Plugins/.../index.js — hand-patched to match (see note below)

Note on the build

This environment's outbound network access to the Umbraco prerelease npm registry (myget.org) is blocked by org policy, so npm run build could not be run to regenerate the bundle here. Unlike the v6 fix, there was no existing PR with a pre-built bundle for this exact change to reuse, so the compiled index.js was hand-patched to mirror the source diff exactly — the built output for this file is unminified/readable enough that the change is a direct, verifiable 1:1 match of the TS diff (confirmed via node --check). The corresponding sourcemap was not regenerated and is now slightly stale for this file. A maintainer with build access should run npm run build to produce a clean bundle + sourcemap before release.

Test plan

  • node --check on the hand-patched bundle passes
  • Maintainer: run npm run build to regenerate a clean bundle/sourcemap
  • Manual verification in the test site: add a new area-carrying block to a Block Grid property without saving and confirm the preview renders with the "Add new Layout" button, and that existing saved blocks with area content still render correctly (Block Grid area previews can render before layoutAreas are available in 5.4.0 #293 regression check)

Generated by Claude Code

Same root cause and fix as the v6 line: UmbBlockGridEntryContext
derives layoutAreas as layout?.areas, and a brand-new block starts
with an empty layout entry, so layoutAreas stays undefined until
content is added to an area or the document is saved and reloaded.
The #293 guard deferred the initial render whenever a block had
configured areas but layoutAreas hadn't arrived yet, and for new
blocks that guard never released, leaving the preview permanently
blank.

Remove the defer/early-return so new blocks render immediately;
#filterLayouts() already defaults each area's items to [] when
layoutAreas is missing, and the existing re-render trigger in
observeBlockValue still fires once real layoutAreas data arrives,
preserving the #293 fix for saved blocks.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J3ybE1j7L5X32L7k4mvgYz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants