Conversation
Move the rendered range for each keyed x-for item so output from nested x-if and x-for templates stays attached during reordering
An empty nested loop could leave the parent's saved last-rendered element pointing at an already removed node, so reordering the parent later moved the wrong range and detached sibling content. Recompute the marker from the last live lookup entry and move the rendered range through its recorded end.
x-for eagerly resolved the last lookup element before storing it, even though moveBlock resolves the marker chain when reading the block boundary. Store the lookup element directly and keep resolution at the use site. This preserves the links between nested structural directives, allowing an outer x-for to resolve the current boundary after an inner x-if removes its rendered child.
moveBlock relocates a contiguous DOM range bounded by its first and last rendered nodes. Use nextSibling instead of nextElementSibling so the entire range moves together. Using nextElementSibling could split the range by leaving intervening text and comment nodes behind.
Rename getLastRenderedElement to resolveBlockEnd and move it into utils/blocks.js for reuse
x-for now keeps a chain of links instead of saving a last node that may later be removed by a nested directive. Follow this chain before getting the next sibling, so morph continues after the rendered block instead of inside it. GPT-6 Astra helped identify the need for this change.
Swapping two items in the data could also move intervening DOM blocks, causing focused inputs in those blocks to lose focus. Swap complete DOM ranges so intervening blocks stay connected. Add regression tests for ordinary elements and nested template blocks. GPT-6 Astra helped uncover a focus regression.
Bring the x-for tests written during the nested reordering fix into the main suite. Cover state preservation, cleanup, changing block boundaries and combined updates. Also add morph regression tests for boundary-handling issues identified with help from GPT-6 Astra.
This branch has not been deployed
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.
Fix reordering when an
x-fortemplate contains nestedx-fororx-iftemplates.Fixes #4911