Skip to content

Commit

Permalink
Highlight issue when a lazy boundary returns a fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jul 8, 2024
1 parent 212b1f6 commit c4b3387
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 30 additions & 0 deletions compat/test/browser/suspense-hydration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,36 @@ describe('suspense hydration', () => {
});
});

it('Should hydrate a fragment with multiple children correctly', () => {
scratch.innerHTML = '<div>Hello</div><div>World!</div>';
clearLog();

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

return resolve(() => (
<>
<div>Hello</div>
<div>World!</div>
</>
)).then(() => {
rerender();
expect(scratch.innerHTML).to.equal('<div>Hello</div><div>World!</div>');
expect(getLog()).to.deep.equal([]);

clearLog();
});
});

it('should allow siblings to update around suspense boundary', () => {
scratch.innerHTML = '<div>Count: 0</div><div>Hello</div>';
clearLog();
Expand Down
3 changes: 2 additions & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function diff(
if (oldVNode._flags & MODE_SUSPENDED) {
isHydrating = !!(oldVNode._flags & MODE_HYDRATE);
oldDom = newVNode._dom = oldVNode._dom;
excessDomChildren = [oldDom];
excessDomChildren = oldVNode._excess;

Check failure on line 56 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test

Property '_excess' does not exist on type 'VNode<any>'.

Check failure on line 56 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test / Build & Test

Property '_excess' does not exist on type 'VNode<any>'.
}

if ((tmp = options._diff)) tmp(newVNode);
Expand Down Expand Up @@ -277,6 +277,7 @@ export function diff(
newVNode._flags |= isHydrating
? MODE_HYDRATE | MODE_SUSPENDED
: MODE_HYDRATE;
newVNode._excess = [...excessDomChildren];

Check failure on line 280 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test

Property '_excess' does not exist on type 'VNode<any>'.

Check failure on line 280 in src/diff/index.js

View workflow job for this annotation

GitHub Actions / Build & Test / Build & Test

Property '_excess' does not exist on type 'VNode<any>'.
excessDomChildren[excessDomChildren.indexOf(oldDom)] = null;
// ^ could possibly be simplified to:
// excessDomChildren.length = 0;
Expand Down

0 comments on commit c4b3387

Please sign in to comment.