From c9846f13393baef888629c219367ba23c5f2e739 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sat, 12 Oct 2024 10:13:41 +0200 Subject: [PATCH] We should not always set to hydration (#4529) * We should not always set to hydration * Update compat/test/browser/suspense-hydration.test.js --- compat/test/browser/suspense.test.js | 19 +++++++++++++++++++ src/diff/index.js | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compat/test/browser/suspense.test.js b/compat/test/browser/suspense.test.js index a7d3c8b7a5..5c7ad45294 100644 --- a/compat/test/browser/suspense.test.js +++ b/compat/test/browser/suspense.test.js @@ -299,6 +299,25 @@ describe('suspense', () => { }); }); + it('should not duplicate DOM when suspending while rendering', () => { + scratch.innerHTML = '
Hello
'; + + const [Lazy, resolve] = createLazy(); + render( + + + , + scratch + ); + rerender(); // Flush rerender queue to mimic what preact will really do + expect(scratch.innerHTML).to.equal(''); + + return resolve(() =>
Hello
).then(() => { + rerender(); + expect(scratch.innerHTML).to.equal('
Hello
'); + }); + }); + it('should suspend when a promise is thrown', () => { class ClassWrapper extends Component { render(props) { diff --git a/src/diff/index.js b/src/diff/index.js index 287f94344d..ae2d77ffc2 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -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;