Skip to content

Commit

Permalink
We should not always set to hydration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Oct 12, 2024
1 parent 675bcad commit 58573ea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
25 changes: 1 addition & 24 deletions compat/test/browser/suspense-hydration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -97,30 +98,6 @@ describe('suspense hydration', () => {
});
});

it('should leave DOM untouched when suspending while hydrating', () => {
scratch.innerHTML = '<!-- test --><div>Hello</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('<!-- test --><div>Hello</div>');
expect(getLog()).to.deep.equal([]);
clearLog();

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

it('should properly attach event listeners when suspending while hydrating', () => {
scratch.innerHTML = '<div>Hello</div><div>World</div>';
clearLog();
Expand Down
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 58573ea

Please sign in to comment.