Conversation
An onDocumentPatch callback that defers start, for example in a view transition, could let a later patch run first. The later diff was then merged into a tree that lacked the earlier one and rendering failed. Patches now run in the order they were requested, whatever the order of the start calls.
Member
|
I would argue that it is the app's responsibility to keep patches in order, so you only call let transition = false;
let previousTransition = Promise.resolve();
window.addEventListener("phx:start-view-transition", () => (transition = true));
let liveSocket = new window.LiveView.LiveSocket("/live", window.Phoenix.Socket, {
dom: {
onDocumentPatch(start) {
// Capture the flag now, so it applies to this patch even if we wait
const animate = transition;
transition = false;
previousTransition = previousTransition
.then(() => {
if (animate && document.startViewTransition) {
return document.startViewTransition(start).finished;
}
start();
})
.catch((err) => console.error(err)); // keep the chain alive if a transition fails
}
}
});We can adjust the docs to state that order has to be preserved manually. |
Contributor
Author
|
Makes sense, thanks. I changed the PR to a short docs note on |
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.
LiveView does not reorder the
startcallbacks it passes toonDocumentPatch. When an app delays only some patches, for example to run a view transition only when the server asks for one, a later patch can run before an earlier one. The client then crashes inRendered.dynamicsToBufferwithCannot read properties of undefined (reading 'length').As discussed in #4462 (comment), keeping the order is the app's job. This PR drops the code change and adds the rule to the
onDocumentPatchdocs.