-
-
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
fix(Suspense): switch suspense cause error in the Keepalive (fix: #6416) #6467
Conversation
this seems not to fix #6463. see demo with your deploy preview |
yes...I misunderstood the difference between #6416 and #6463,seem my pr only fix #6416, |
@@ -321,7 +321,7 @@ function patchSuspense( | |||
triggerEvent(n2, 'onPending') | |||
// mount pending branch in off-dom container | |||
suspense.pendingBranch = newBranch | |||
suspense.pendingId++ | |||
if (suspense.pendingId > 0) suspense.pendingId-- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the root cause is: the newBranch is cached in keepalive and its suspenseId not updated when pendingId++. if we update the suspenseId of newBranch will be ok.
likely:
if (
parentComponent &&
(parentComponent.vnode.type as any).__isKeepAlive &&
newBranch.component
) {
newBranch.component.suspenseId = suspense.pendingId
}
@@ -42,7 +42,7 @@ export const nodeOps: Omit<RendererOptions<Node, Element>, 'patchProp'> = { | |||
el.textContent = text | |||
}, | |||
|
|||
parentNode: node => node.parentNode as Element | null, | |||
parentNode: node => (node ? node.parentNode : null) as Element | null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is unnecessary.
@@ -212,7 +212,7 @@ function setElementText(el: TestElement, text: string) { | |||
} | |||
|
|||
function parentNode(node: TestNode): TestElement | null { | |||
return node.parentNode | |||
return node ? node.parentNode : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is unnecessary.
Hello, any progress with this PR? Need any help? |
Thank you for your kindness!, but this PR should be suspended first as the reason for this bug is complex,I think it needs further study。 |
Thanks for the PR - although this isn't the correct fix, I reused your test case in aa0c13f |
Fixes #6416
I wrote a test case to replicate the bug in Suspense.spec.ts。
This bug occurs for two reasons
Here's a video demo of the fix: https://www.bilibili.com/video/BV1Cd4y1R7bU/
and SFC Playground demo of this fix:my demo