-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<Transition>
wrapped by <Suspense>
breaks entirely if interrupted before it completes
#8105
Comments
This rings a bell, there could be another open issue about interrupting a transition here but I couldn't find it. It looks similar to #6835 but clearly not the same. |
After some investigations, I've found a workaround to relief the issue with the following patch. --- packages/runtime-dom/src/nodeOps.ts
+++ packages/runtime-dom/src/nodeOps.ts
@@ -6,8 +6,18 @@ const doc = (typeof document !== 'undefined' ? document : null) as Document
const templateContainer = doc && /*#__PURE__*/ doc.createElement('template')
+function isSafeAnchor(parent: Element, anchor: Node | null | undefined) {
+ if (!anchor) return true;
+
+ for (let node: Node | null = anchor; node; node = node.parentNode) {
+ if (parent === node) return true;
+ }
+ return false;
+}
+
export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = {
insert: (child, parent, anchor) => {
+ if (!isSafeAnchor(parent, anchor)) anchor = null;
parent.insertBefore(child, anchor || null)
}, It also works on nuxt/nuxt#13350 I also came up with logs that what's happend internally; Good case:
Bad case:
I hope it helps. |
core/packages/runtime-core/src/components/Suspense.ts Lines 497 to 520 in d2c3d8b
The issue happens when Just to be confirmed, removing |
After deep investigation, I've finally found the solution. --- packages/runtime-core/src/renderer.ts
+++ packages/runtime-core/src/renderer.ts
@@ -2035,6 +2035,7 @@ function baseCreateRenderer(
if (needTransition) {
if (moveType === MoveType.ENTER) {
transition!.beforeEnter(el!)
+ if (anchor && anchor.parent !== container) anchor = null;
hostInsert(el!, container, anchor)
queuePostRenderEffect(() => transition!.enter(el!), parentSuspense)
} else { The Perhaps, it should be re-calculate |
I've posted a PR (based on another idea), and I've noticed that the same pattern causes the same error, btw. For example, following lines cause a HMR issue. (failed to reload a page sometimes) core/packages/runtime-core/src/renderer.ts Lines 374 to 375 in 9f8e98a
After patching the same way in the PR like this, it has been resolved. const anchorCands: RendererNode[] = []
for (let node = getNextHostNode(n1); node; node = hostNextSibling(node)) {
anchorCands.push(node)
}
unmount(n1, parentComponent, parentSuspense, true)
anchor = anchorCands.find(x => hostParentNode(x) === container) || null; In current code, |
I'm trying to explain what's going on under the hood. For this issue, there are 2 cases:
Additionally:
|
Fix page transitions. Turns out there is a bug in Vue itself. Fixed by adding a div to make sure there is only one root element. vuejs/core#8105 Localization of route navigation was missing in a few places. Update nuxt dev server to host on local network. This way the application can be viewed on mobile. Fix a-tag underlines showing on mobile. Also added global style sheet, main.scss.
Yay!! 🙌🏼 |
🎉 Thank you @edison1105 |
Thank you to everyone involved in resolving this problem 🙏 |
When I opened my notifications today Thanks a lot everyone and thank you @yyx990803 for getting the merge train rolling! |
Vue version
3.2.47
Link to minimal reproduction
https://stackblitz.com/edit/github-z3ry59-hbu5x7
SFC Playground
Steps to reproduce
Click the button marked 'Trigger error'.
This will switch components within the Transition. On next tick, it will switch them back. (To reproduce, it's sufficient to switch them at any point before the transition has finished.)
Note that this follows the component order specified in https://vuejs.org/guide/built-ins/suspense.html#combining-with-other-components.
What is expected?
I expect no errors.
What is actually happening?
The following error is thrown:
In addition, the content of the Suspense slot is removed and the page remains broken.
System Info
No response
Any additional comments?
No response
The text was updated successfully, but these errors were encountered: