Fix site editor crash when query loop has multiple post-templates#25
Open
mattheu wants to merge 1 commit into
Open
Fix site editor crash when query loop has multiple post-templates#25mattheu wants to merge 1 commit into
mattheu wants to merge 1 commit into
Conversation
getBlock() can transiently return null in the site editor when a template includes a pattern block whose inner blocks land in the name index before their full record exists in byClientId. The resulting null in the postTemplates array crashed withPostTemplateStyles and withPostTemplateInspectorControls when they accessed postTemplate.clientId. Fix: filter nulls out of the getBlock() results in withQueryLoopContextProvider so consumers always receive valid block objects. Also fixes a secondary issue: when perPage is undefined (no limit set on a post-template) the hideAfterLimit CSS rule evaluated to nth-of-type(n+NaN), an invalid selector. Suppress the rule entirely when perPage is not set — no limit means no posts should be hidden. Reproducer: open the site editor and edit any template that embeds a pattern containing a core/query block with two core/post-template children (e.g. the editors-pick-opinion pattern on an AGBI opinion archive template). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Playwright test resultsDetails
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Opening any template in the site editor that contains a pattern with a
core/queryblock having two or morecore/post-templatechildren crashes the editor with a TypeError. The AGBI opinion archive template reproduces this via theeditors-pick-opinionpattern, which uses a two-column layout (1 featured card + 4 grid cards) inside a single query.Root cause
withQueryLoopContextProviderpopulatesUsedPostsContextby calling:getBlock()can transiently returnnullin the site editor when a pattern block's inner blocks are registered in the block-name index before their full record is written tobyClientId(the two store structures are updated in separate microtasks during initial block-tree construction). This leavesnullvalues in thepostTemplatesarray.Both
withPostTemplateStylesandwithPostTemplateInspectorControlsthen iteratepostTemplatesand accesspostTemplate.clientIdwithout a null guard — throwingTypeError: Cannot read properties of null (reading 'clientId')and crashing the editor.This was masked in ≤ 0.4.x because
withUniqueQueryIdalways calledsetAttributeson first render, forcing a store update + re-render cycle that resolved the transient null state before any consumer ran. The 0.7.0 fix (preserve unique queryIds) eliminated that forced re-render, exposing the latent race.Fix
Filter nulls from
getBlock()results inwithQueryLoopContextProviderso consumers always receive valid block objects:Guard the
hideAfterLimitCSS rule againstperPage = undefined: without a perPage limit the expressionoffset + undefined + 2evaluates toNaN, producing the invalid selectornth-of-type(n+NaN). Suppress the rule entirely when no limit is set (correct behaviour — if there's no limit, no posts should be hidden).Testing
core/querywith twocore/post-templatechildrenperPageis set🤖 Generated with Claude Code