Skip to content

Commit

Permalink
We should not always set to hydration (#4529)
Browse files Browse the repository at this point in the history
* We should not always set to hydration

* Update compat/test/browser/suspense-hydration.test.js
  • Loading branch information
JoviDeCroock authored Oct 12, 2024
1 parent 675bcad commit c9846f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions compat/test/browser/suspense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,25 @@ describe('suspense', () => {
});
});

it('should not duplicate DOM when suspending while rendering', () => {
scratch.innerHTML = '<div>Hello</div>';

const [Lazy, resolve] = createLazy();
render(
<Suspense>
<Lazy />
</Suspense>,
scratch
);
rerender(); // Flush rerender queue to mimic what preact will really do
expect(scratch.innerHTML).to.equal('');

return resolve(() => <div>Hello</div>).then(() => {
rerender();
expect(scratch.innerHTML).to.equal('<div>Hello</div>');
});
});

it('should suspend when a promise is thrown', () => {
class ClassWrapper extends Component {
render(props) {
Expand Down
2 changes: 1 addition & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function diff(
if (isHydrating || excessDomChildren != null) {
newVNode._flags |= isHydrating
? MODE_HYDRATE | MODE_SUSPENDED
: MODE_HYDRATE;
: MODE_SUSPENDED;

while (oldDom && oldDom.nodeType === 8 && oldDom.nextSibling) {
oldDom = oldDom.nextSibling;
Expand Down

0 comments on commit c9846f1

Please sign in to comment.