fix: resolve SSR hydration ordinal drift from structural blocks#216
Merged
mohamedmansour merged 2 commits intomainfrom Apr 10, 2026
Merged
fix: resolve SSR hydration ordinal drift from structural blocks#216mohamedmansour merged 2 commits intomainfrom
mohamedmansour merged 2 commits intomainfrom
Conversation
and count element/text ordinals to map compiled template paths to SSR DOM nodes. When conditional (<if>) or repeat (<for>) blocks render content into the SSR DOM, the extra nodes shift ordinals so later siblings resolve to the wrong element. Root cause: the compiled template static HTML (meta.h) strips structural blocks, but the SSR DOM contains them inline between marker pairs (<!--wc-->...<!--/wc--> and <!--wr-->...<!--/wr-->). The ordinal counting did not account for these extra ranges. This manifested in the commerce app when navigating from a zero-result search page (/search?q=test) to a category: the <for> loop's parent container resolved to the <p> no-results message instead of <div class=grid>, leaving the product grid empty after SPA navigation. Framework changes (webui-framework): - Extract findByOrdinal() into markers.ts — walks parent children counting only nodes outside structural block marker pairs, with depth tracking for nested blocks of the same type. Both (element ordinals) and (text ordinals) now delegate to this single function. - Defer SSR marker removal — closing markers (<!--/wc-->, <!--/wr-->) and item markers (<!--wi-->) are collected during hydration but only removed after all path-based resolution is complete (after for events/refs). This ensures marker pairs are intact whenever findByOrdinal needs to skip structural blocks, regardless of hydration phase ordering. - Add 10 unit tests for findByOrdinal covering: conditional skipping, repeat skipping, nested conditionals, multiple sequential blocks, empty blocks, text ordinal drift, interleaved block types, and edge cases (empty parent, out-of-range ordinal). Commerce app changes: - Fix mp-category-nav @attr mode — change all-active from string mode (default '') to boolean mode (default false). String mode produced '' (falsy) from the boolean attribute, causing a hydration mismatch where the server-rendered <if condition=allActive> block was not tracked by the client, leaving orphaned 'All' DOM nodes visible after SPA navigation. - Fix Related Products scrollbar visibility — the scrollbar thumb used --webui-border (#262626), the same color as the track (--webui-surface #262626), making it invisible. Changed to --webui-text-muted and added scrollbar-width/scrollbar-color for Firefox cross-browser support. - Add regression test for search→category SPA navigation verifying category nav state and product grid population. - Update visual regression snapshots. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
akroshg
reviewed
Apr 10, 2026
akroshg
reviewed
Apr 10, 2026
akroshg
approved these changes
Apr 10, 2026
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.
Compiled template paths to SSR DOM nodes. When conditional () or repeat () blocks render content into the SSR DOM, the extra nodes shift ordinals so later siblings resolve to the wrong element.
Root cause: the compiled template static HTML (meta.h) strips structural blocks, but the SSR DOM contains them inline between marker pairs (... and ...). The ordinal counting did not account for these extra ranges.
This manifested in the commerce app when navigating from a zero-result search page (/search?q=test) to a category: the loop's parent container resolved to the
no-results message instead of
Framework changes (webui-framework):
Extract findByOrdinal() into markers.ts — walks parent children counting only nodes outside structural block marker pairs, with depth tracking for nested blocks of the same type. Both (element ordinals) and (text ordinals) now delegate to this single function.
Defer SSR marker removal — closing markers (, ) and item markers () are collected during hydration but only removed after all path-based resolution is complete (after for events/refs). This ensures marker pairs are intact whenever findByOrdinal needs to skip structural blocks, regardless of hydration phase ordering.
Add 10 unit tests for findByOrdinal covering: conditional skipping, repeat skipping, nested conditionals, multiple sequential blocks, empty blocks, text ordinal drift, interleaved block types, and edge cases (empty parent, out-of-range ordinal).
Commerce app changes:
Fix mp-category-nav @attr mode — change all-active from string mode (default '') to boolean mode (default false). String mode produced '' (falsy) from the boolean attribute, causing a hydration mismatch where the server-rendered block was not tracked by the client, leaving orphaned 'All' DOM nodes visible after SPA navigation.
Fix Related Products scrollbar visibility — the scrollbar thumb used --webui-border (#262626), the same color as the track (--webui-surface #262626), making it invisible. Changed to --webui-text-muted and added scrollbar-width/scrollbar-color for Firefox cross-browser support.
Add regression test for search→category SPA navigation verifying category nav state and product grid population.