fix: reconcile prerendered content a content binding does not adopt#7639
Open
AKnassa wants to merge 1 commit into
Open
fix: reconcile prerendered content a content binding does not adopt#7639AKnassa wants to merge 1 commit into
AKnassa wants to merge 1 commit into
Conversation
A content binding hydrates by adopting the nodes the server rendered between its boundary markers. When it could not adopt them it left them in the DOM owned by no view, so nothing ever bound them, and once the value resolved a second, client-rendered copy was composed alongside them. This happens when a `when` condition is falsy as the element hydrates but the server rendered the branch, which is the case whenever the condition depends on data that has not resolved yet. `repeat` is unaffected because it reconciles its prerendered item views against the live DOM instead. Discard the prerendered range the binding does not adopt, consuming the boundary so a range is discarded at most once. Adds a fast-html hydration fixture covering a `defer-and-hydrate` child rendered inside a conditional content binding, with the equivalent repeat binding as a control. Fixes microsoft#7634
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
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.
What this does
Fixes a bug where a component placed inside an
<if>(awhenbinding) could quietly break after a page is server-rendered and then brought to life in the browser. The component would show up on screen but be completely dead — it never responded to data — and sometimes a second copy of it appeared next to the first.Fixes #7634.
Why
If a page is rendered on the server with the
<if>condition true, the server sends down the content inside it. When the browser takes over, the condition may not be true yet — typically because the data it depends on hasn't loaded. When that happened, the content the server sent was left sitting in the page with nothing looking after it. Nothing ever connected it to the data, so it stayed frozen forever, and once the data did arrive a fresh copy was added beside it.The same component inside a
<for each>(arepeatbinding) always worked, becauserepeattidies up server-rendered content it can't reuse.<if>didn't. That's the whole difference, and it's why the known workaround was to swap<if>for a one-item<for each>.What changed
repeatalready does — so nothing is left orphaned, and no duplicate appears.defer-and-hydratecomponent inside an<if>, with the same component inside a<for each>alongside it as a control, so the two are held to the same standard from now on.No public API changed.
How to see it
The new fixture is
packages/fast-html/test/fixtures/when-nested-elements/.Two of those tests fail without the change and pass with it. Full suites are green on Chromium, Firefox and WebKit: fast-element 4281 passing, fast-html 987 passing.
Notes for reviewers
A few things worth your judgement:
fast-element-2.x, since that's wherefast-htmland fast-element 2.x live.mainis fast-element 3.0.1 and has nofast-htmlpackage, so this scenario can't arise there.when, andbindingViewBoundariesis populated for it — so the missing-boundary theory in the report isn't the cause. The real problem is that the content binding never reconciles a range it doesn't adopt.defer-hydration/needs-hydrationforever). What does reproduce, from the same root cause and the same code path, is the orphaned-plus-duplicated content fixed here. If you have a repro of the attribute-retention symptom, I'd like to check it against this.fast-html, notfast-element, because it needs the real server renderer and its markers. Both run in this repo's CI, so the fix is guarded — but fast-element's own suite doesn't cover it.RenderBehavior.bindinrender.tsreads the same boundaries and, if they're missing, renders nothing at all. Looks like the same family of bug, but out of scope here.