Skip to content

Commit 852f511

Browse files
committed
Publish fixes for streaming renders
1 parent f7f9d9b commit 852f511

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

compat/test/browser/suspense-hydration.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ describe('suspense hydration', () => {
9797
});
9898
});
9999

100+
it('should leave DOM untouched when suspending while hydrating', () => {
101+
scratch.innerHTML = '<!-- test --><div>Hello</div>';
102+
clearLog();
103+
104+
const [Lazy, resolve] = createLazy();
105+
hydrate(
106+
<Suspense>
107+
<Lazy />
108+
</Suspense>,
109+
scratch
110+
);
111+
rerender(); // Flush rerender queue to mimic what preact will really do
112+
expect(scratch.innerHTML).to.equal('<!-- test --><div>Hello</div>');
113+
expect(getLog()).to.deep.equal([]);
114+
clearLog();
115+
116+
return resolve(() => <div>Hello</div>).then(() => {
117+
rerender();
118+
expect(scratch.innerHTML).to.equal('<!-- test --><div>Hello</div>');
119+
expect(getLog()).to.deep.equal([]);
120+
clearLog();
121+
});
122+
});
123+
100124
it('should properly attach event listeners when suspending while hydrating', () => {
101125
scratch.innerHTML = '<div>Hello</div><div>World</div>';
102126
clearLog();

src/diff/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,15 @@ export function diff(
273273
newVNode._original = null;
274274
// if hydrating or creating initial tree, bailout preserves DOM:
275275
if (isHydrating || excessDomChildren != null) {
276-
newVNode._dom = oldDom;
277276
newVNode._flags |= isHydrating
278277
? MODE_HYDRATE | MODE_SUSPENDED
279278
: MODE_HYDRATE;
279+
280+
while (oldDom && oldDom.nodeType === 8 && oldDom.nextSibling) {
281+
oldDom = oldDom.nextSibling;
282+
}
280283
excessDomChildren[excessDomChildren.indexOf(oldDom)] = null;
281-
// ^ could possibly be simplified to:
282-
// excessDomChildren.length = 0;
284+
newVNode._dom = oldDom;
283285
} else {
284286
newVNode._dom = oldVNode._dom;
285287
newVNode._children = oldVNode._children;

0 commit comments

Comments
 (0)