refactor: Extract Block Grid render-timing decision into a pure, tested module - #330
Open
rickbutterfield wants to merge 3 commits into
Open
refactor: Extract Block Grid render-timing decision into a pure, tested module#330rickbutterfield wants to merge 3 commits into
rickbutterfield wants to merge 3 commits into
Conversation
…scheduler Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replaces the element's inline layoutAreas/resize conditionals with calls to decideGridRenderTrigger/shouldDeferInitialGridRender, and the ad-hoc setTimeout/clearTimeout pair with ResizeDebouncer, both from Task 1's render-scheduler.ts. Adds an element-level regression test (grid-render-timing.test.ts) that drives real observable state through the element to prove the wiring, not just the pure functions, for issues #293/#294.
…disconnect Addresses two whole-branch review findings on the render-scheduler extraction: document and test that decideGridRenderTrigger intentionally collapses the old two-independent-if-blocks behavior (render always wins over debounce when both conditions hold on the same emission), and cancel the pending ResizeDebouncer timer in BlockGridPreviewCustomView.disconnectedCallback so it can't fire renderBlockPreview() after the element is removed from the DOM. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
Extracts the Block Grid preview's "should I re-render yet" decision — previously four mutable fields read via inline conditionals at two call sites in
block-grid-preview.custom-view.element.ts— into a new, pure, independently unit-tested module (render-scheduler.ts).decideGridRenderTrigger/shouldDeferInitialGridRender— pure functions, no DOM, nothis, no timers.ResizeDebouncer— replaces the inlinesetTimeout/clearTimeoutpair.BlockGridPreviewCustomViewis wired to call these instead of inlining the logic.This is the render-timing decision behind issues #293/#294 (Block Grid area previews rendering blank or before layout data was available) — it had never had a dedicated unit test until this branch. A new element-level test (
grid-render-timing.test.ts) drives real observable state through the element to prove the wiring reproduces the fix end-to-end, not just that the extracted functions are individually correct.One subtle, deliberate behavior change surfaced during review: the pure function's single-return-value design makes the "layoutAreas arrived" and "resize" triggers mutually exclusive on the same observable emission, where the old code could fire both (an immediate render plus a redundant 300ms-later one). This is locked down with an explicit test and comment rather than left implicit — the likely effect is one fewer redundant preview request, not a behavior regression.
Scoped to Block Grid only — List/Single/RichText don't have this timing complexity and are untouched. A follow-on plan (collapsing all four preview elements onto shared descriptors) is intentionally out of scope here.
Test plan
npm test— 32/32 passing🤖 Generated with Claude Code