Skip to content

Commit 9e469c3

Browse files
committed
ensure we carry over suspense
1 parent cf4d9b7 commit 9e469c3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/router.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,20 @@ export function Router(props) {
132132
if (matches) return (pr = cloneElement(vnode, m));
133133
if (vnode.props.default) d = cloneElement(vnode, m);
134134
});
135+
const isHydratingSuspense = cur.current && cur.current.__u & MODE_HYDRATE && cur.current.__u & MODE_SUSPENDED;
135136
cur.current = h(RouteContext.Provider, { value: m }, pr || d);
137+
if (isHydratingSuspense) {
138+
cur.current.__u |= MODE_HYDRATE;
139+
cur.current.__u |= MODE_SUSPENDED;
140+
141+
}
136142

137143
// Reset previous children - if rendering succeeds synchronously, we shouldn't render the previous children.
138144
const p = prev.current;
139145
prev.current = null;
140146

141147
// This borrows the _childDidSuspend() solution from compat.
142-
this.__c = e => {
148+
this.__c = (e, suspendedVNode) => {
143149
// Mark the current render as having suspended:
144150
didSuspend.current = true;
145151

@@ -158,6 +164,16 @@ export function Router(props) {
158164

159165
// Successful route transition: un-suspend after a tick and stop rendering the old route:
160166
prev.current = null;
167+
if (cur.current) {
168+
if (suspendedVNode.__u & MODE_SUSPENDED) {
169+
cur.current.__u |= MODE_SUSPENDED;
170+
}
171+
172+
if (suspendedVNode.__u & MODE_HYDRATE) {
173+
cur.current.__u |= MODE_HYDRATE;
174+
}
175+
}
176+
161177
RESOLVED.then(update);
162178
});
163179
};
@@ -198,6 +214,9 @@ export function Router(props) {
198214
return [h(RenderRef, { r: cur }), h(RenderRef, { r: prev })];
199215
}
200216

217+
const MODE_HYDRATE = 1 << 5;
218+
const MODE_SUSPENDED = 1 << 7;
219+
201220
// Lazily render a ref's current value:
202221
const RenderRef = ({ r }) => r.current;
203222

0 commit comments

Comments
 (0)