From 58573eaedf23f80ee8873fed14af6d289bee9cd4 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Sat, 12 Oct 2024 09:32:17 +0200 Subject: [PATCH] We should not always set to hydration --- .../test/browser/suspense-hydration.test.js | 25 +------------------ compat/test/browser/suspense.test.js | 19 ++++++++++++++ src/diff/index.js | 2 +- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/compat/test/browser/suspense-hydration.test.js b/compat/test/browser/suspense-hydration.test.js index b364cf41c6..0bb3824dc2 100644 --- a/compat/test/browser/suspense-hydration.test.js +++ b/compat/test/browser/suspense-hydration.test.js @@ -15,6 +15,7 @@ import { } from '../../../test/_util/helpers'; import { ul, li, div } from '../../../test/_util/dom'; import { createLazy, createSuspenseLoader } from './suspense-utils'; +import { render } from 'preact'; /* eslint-env browser, mocha */ describe('suspense hydration', () => { @@ -97,30 +98,6 @@ describe('suspense hydration', () => { }); }); - it('should leave DOM untouched when suspending while hydrating', () => { - scratch.innerHTML = '
Hello
'; - clearLog(); - - const [Lazy, resolve] = createLazy(); - hydrate( - - - , - scratch - ); - rerender(); // Flush rerender queue to mimic what preact will really do - expect(scratch.innerHTML).to.equal('
Hello
'); - expect(getLog()).to.deep.equal([]); - clearLog(); - - return resolve(() =>
Hello
).then(() => { - rerender(); - expect(scratch.innerHTML).to.equal('
Hello
'); - expect(getLog()).to.deep.equal([]); - clearLog(); - }); - }); - it('should properly attach event listeners when suspending while hydrating', () => { scratch.innerHTML = '
Hello
World
'; clearLog(); 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;