Skip to content

Commit

Permalink
Merge branch 'main' into test-out-comment-markers
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jul 18, 2024
2 parents 02560eb + a75b217 commit f74d6cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
41 changes: 5 additions & 36 deletions compat/test/browser/suspense-hydration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ describe('suspense hydration', () => {
});
});

it('Should hydrate a fragment with no children correctly', () => {
scratch.innerHTML = '<!--$s--><!--/$s-->';
it('should leave DOM untouched when suspending while hydrating', () => {
scratch.innerHTML = '<!-- test --><div>Hello</div>';
clearLog();

const [Lazy, resolve] = createLazy();
Expand All @@ -143,45 +143,14 @@ describe('suspense hydration', () => {
scratch
);
rerender(); // Flush rerender queue to mimic what preact will really do
expect(scratch.innerHTML).to.equal('<!--$s--><!--/$s-->');
expect(getLog()).to.deep.equal([]);
clearLog();

return resolve(() => null).then(() => {
rerender();
expect(scratch.innerHTML).to.equal('<!--$s--><!--/$s-->');
expect(getLog()).to.deep.equal([]);

clearLog();
});
});

// This is in theory correct but still it shows that our oldDom becomes stale very quickly
// and moves DOM into weird places
it('Should hydrate a fragment with no children and an adjacent node correctly', () => {
scratch.innerHTML = '<!--$s--><!--/$s--><div>Baz</div>';
clearLog();

const [Lazy, resolve] = createLazy();
hydrate(
<>
<Suspense>
<Lazy />
</Suspense>
<div>Baz</div>
</>,
scratch
);
rerender(); // Flush rerender queue to mimic what preact will really do
expect(scratch.innerHTML).to.equal('<!--$s--><!--/$s--><div>Baz</div>');
expect(scratch.innerHTML).to.equal('<!-- test --><div>Hello</div>');
expect(getLog()).to.deep.equal([]);
clearLog();

return resolve(() => null).then(() => {
return resolve(() => <div>Hello</div>).then(() => {
rerender();
expect(scratch.innerHTML).to.equal('<!--$s--><!--/$s--><div>Baz</div>');
expect(scratch.innerHTML).to.equal('<!-- test --><div>Hello</div>');
expect(getLog()).to.deep.equal([]);

clearLog();
});
});
Expand Down
3 changes: 3 additions & 0 deletions src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ export function diff(
}

if (shouldFallback) {
while (oldDom && oldDom.nodeType === 8 && oldDom.nextSibling) {
oldDom = oldDom.nextSibling;
}
excessDomChildren[excessDomChildren.indexOf(oldDom)] = null;
newVNode._component._excess.push(oldDom);
}
Expand Down

0 comments on commit f74d6cd

Please sign in to comment.