Skip to content

Commit 547ee9a

Browse files
committed
Derive unmount error routing from vnode._parent, dropping the options.unmount parentVNode arg
1 parent e584f74 commit 547ee9a

4 files changed

Lines changed: 15 additions & 10 deletions

File tree

compat/src/suspense.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ options._catchError = (error, newVNode, oldVNode, errorInfo) => {
2929
};
3030

3131
const oldUnmount = options.unmount;
32-
options.unmount = (vnode, parentVNode) => {
32+
options.unmount = vnode => {
3333
/** @type {import('./internal').Component} */
3434
const component = vnode._component;
3535
if (component) component._unmounted = true;
3636
if (component && component._onResolve) {
3737
component._onResolve();
3838
}
3939

40-
if (oldUnmount) oldUnmount(vnode, parentVNode);
40+
if (oldUnmount) oldUnmount(vnode);
4141
};
4242

4343
function detachedClone(vnode, detachedParent, parentDom) {

hooks/src/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,23 @@ options._commit = (vnode, commitQueue) => {
124124
if (oldCommit) oldCommit(vnode, commitQueue);
125125
};
126126

127-
/** @type {(vnode: import('./internal').VNode, parentVNode?: import('./internal').VNode) => void} */
128-
options.unmount = (vnode, parentVNode) => {
129-
if (oldBeforeUnmount) oldBeforeUnmount(vnode, parentVNode);
127+
/** @type {(vnode: import('./internal').VNode) => void} */
128+
options.unmount = vnode => {
129+
if (oldBeforeUnmount) oldBeforeUnmount(vnode);
130130

131131
const c = vnode._component;
132132
if (c && c.__hooks) {
133133
let hasErrored,
134-
errorParent = parentVNode && parentVNode._parent;
134+
errorParent = vnode._parent;
135135
// The removed subtree is detached (`_parent` nulled) by flush time, so
136136
// grab the nearest surviving component now; its current vnode can still
137-
// route deferred cleanup errors to a mounted error boundary.
138-
while (errorParent && !errorParent._component) {
137+
// route deferred cleanup errors to a mounted error boundary. Unmounting
138+
// is pre-order and nulls each component's `_parentDom` before its
139+
// children unmount, so removed ancestors are already recognizable here.
140+
while (
141+
errorParent &&
142+
!(errorParent._component && errorParent._component._parentDom)
143+
) {
139144
errorParent = errorParent._parent;
140145
}
141146
c.__hooks._list.some(s => {

src/diff/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ export function applyRef(ref, value, vnode) {
752752
*/
753753
export function unmount(vnode, parentVNode, skipRemove) {
754754
let r;
755-
if (options.unmount) options.unmount(vnode, parentVNode);
755+
if (options.unmount) options.unmount(vnode);
756756

757757
if ((r = vnode.ref) && (!r.current || r.current == vnode._dom)) {
758758
applyRef(r, NULL, parentVNode);

src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export interface Options {
306306
/** Attach a hook that is invoked whenever a VNode is created. */
307307
vnode?(vnode: VNode): void;
308308
/** Attach a hook that is invoked immediately before a vnode is unmounted. */
309-
unmount?(vnode: VNode, parentVNode?: VNode): void;
309+
unmount?(vnode: VNode): void;
310310
/** Attach a hook that is invoked after a vnode has rendered. */
311311
diffed?(vnode: VNode): void;
312312
event?(e: Event): any;

0 commit comments

Comments
 (0)