Repository navigation
Fix editor hang from NaN query ID seed in the site editor - #26
Merged
Merged
Conversation
withUniqueQueryId seeds generated ids with `postId * 1000`, where postId comes from `getCurrentPostId()`. In the post editor that is a numeric post ID, but in the site editor it is the template's string id (`theme//archive-opinion`), so the seed is NaN. NaN then poisons both comparisons the HOC relies on: - `NaN !== NaN` is always true, so the useEffect rewrote queryId on every render, marking the template dirty. - `[ NaN ].includes( NaN )` is true (includes uses SameValueZero, unlike indexOf) and `NaN++` stays NaN, so once any block on the page held a NaN queryId, the dedupe loop added in 64d4c9f never terminated and hung the editor. Any template with two or more query blocks whose ids are missing or duplicated reaches that loop, which is how it surfaced: block themes commonly carry patterns with hardcoded low queryIds alongside templates that omit them. Coerce the seed to a finite number, hashing non-numeric ids into a stable integer. Stability matters as much as finiteness here: a seed that changed between loads would rewrite ids on open and reintroduce the false "unsaved changes" warning 64d4c9f fixed. Post editor behaviour is unchanged, and a finite seed is what guarantees the dedupe loop terminates. The existing queryId tests all run in the post editor, so none covered the string-id path. Add a site editor test asserting ids are finite, unique and stable; it asserts `typeof templateId === 'string'` up front so it fails loudly rather than silently stops covering the bug if core ever returns a numeric id. Number.isFinite is the operative check, since typeof NaN is 'number'.
Playwright test resultsDetails
|
mattheu
approved these changes
Jul 21, 2026
mattheu
left a comment
Member
There was a problem hiding this comment.
Sounds like a good fix.
Make sure to test carefully on a few templates - refer to the testing checklist in confluence and make sure all of these work OK.
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
withUniqueQueryIdseeds ids withpostId * 1000. In the site editorgetCurrentPostId()returns the template's string id (twentytwentyfive//archive), so the seed isNaN.That hangs the editor, because
[ NaN ].includes( NaN )is true (SameValueZero) andNaN++staysNaN— so the dedupe loop added in 64d4c9f never terminates. It also rewritesqueryIdon every render, sinceNaN !== NaN.Triggered by any template with two or more query blocks whose ids are missing or duplicated.
Fix
Coerce the seed to a finite number, hashing non-numeric ids into a stable integer. Finiteness is what makes the loop terminate; stability keeps ids from being rewritten on load. Post editor behaviour is unchanged.