Skip to content

fix: resolve nodeKey for previews nested in block lists#298

Merged
rickbutterfield merged 2 commits into
v5/devfrom
v5/bugfix/297-nested-block-list-nodekey
Jun 30, 2026
Merged

fix: resolve nodeKey for previews nested in block lists#298
rickbutterfield merged 2 commits into
v5/devfrom
v5/bugfix/297-nested-block-list-nodekey

Conversation

@rickbutterfield

Copy link
Copy Markdown
Owner

Summary

Fixes #297 — block previews rendered inside a nested block list failed to resolve their nodeKey, causing the stylesheet API call to fail (empty nodeKeyGuid bind error) or render against a stale node from a previously-visited page.

Root cause

UMB_CONTENT_WORKSPACE_CONTEXT / UMB_DOCUMENT_WORKSPACE_CONTEXT and UMB_BLOCK_WORKSPACE_CONTEXT are all registered under the same context alias ('UmbWorkspaceContext'), distinguished only by a discriminator. Context consumers default to stopping at the first alias match. For a preview nested inside another block, the surrounding block workspace shadowed the document workspace, so the lookup never resolved — and the view fell back to a session-global node-key cache that was either empty or stale (the cross-page leak described in the issue).

Fix

The four custom views (block list, single, grid, rich text) now use passContextAliasMatches on their workspace lookups, so nested previews pass the block workspace and resolve the real document node directly.

Cleanup

Removed now-dead code from BlockPreviewContext:

  • the unused unique / documentTypeUnique observables, and
  • the redundant settings plumbing (it duplicated the settings fetch already performed at startup, i.e. one fewer API call per backoffice load).

The getUnique/setUnique cache and observeBlockWorkspaceFallback are intentionally kept: they remain load-bearing for previews rendered inside a portaled block-edit modal, where no content/document workspace is reachable.

Tests

Added a @web/test-runner setup (the UI project previously had none) and a regression test that mounts the list preview inside a shadowing block workspace and asserts it resolves the document nodeKey. Confirmed it fails before the fix and passes after; a second test guards the non-nested case.

2 passing   |   tsc + vite build: clean

🤖 Generated with Claude Code

Block preview custom views resolved their document nodeKey by reading the
content/document workspace context. That context shares its alias
('UmbWorkspaceContext') with the block workspace context, and context
consumers stop at the first alias match by default. When a preview was
rendered inside another block, the nearer block workspace shadowed the
document workspace, so the lookup never resolved and the view fell back to
a session-global node-key cache — which was either empty (causing the
stylesheet request to fail Guid binding) or stale from a previously
visited node.

The four custom views (block list, single, grid, rich text) now pass
beyond alias matches via passContextAliasMatches, so nested previews
resolve the real document node directly.

Also removes now-dead code from BlockPreviewContext: the unused unique /
documentTypeUnique observables and the redundant settings plumbing (which
duplicated the settings fetch already done at startup).

Adds a web-test-runner regression test that mounts the list preview inside
a shadowing block workspace and asserts it resolves the document nodeKey.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rickbutterfield rickbutterfield changed the title fix: resolve nodeKey for previews nested in block lists (#297) fix: resolve nodeKey for previews nested in block lists Jun 25, 2026
Parametrize the issue #297 regression test across the block list, single,
grid, and rich-text custom views (previously list-only). The rich-text view
consumes UMB_DOCUMENT_WORKSPACE_CONTEXT (matched on getEntityType) with a flat
contentTypeUnique, while the others use UMB_CONTENT_WORKSPACE_CONTEXT (matched
on IS_CONTENT_WORKSPACE_CONTEXT) with structure.contentTypeUniques, so each gets
the appropriate workspace fake.

Also correct a stale comment in BlockPreviewContext describing the node-key
cache fallback, and add a test-scoped tsconfig.test.json (plus @types/mocha) so
the mocha globals in test files resolve without affecting the build tsconfig.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@rickbutterfield rickbutterfield merged commit ea86cee into v5/dev Jun 30, 2026
4 checks passed
@rickbutterfield rickbutterfield deleted the v5/bugfix/297-nested-block-list-nodekey branch June 30, 2026 14:54
rickbutterfield added a commit that referenced this pull request Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant