Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent invalid DOM nesting false positives #4160

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

marvinhagemeister
Copy link
Member

When Preact is rendering into a container in the middle of the page we attempted to walk outside the render root via the DOM tree. Problem is that that doesn't work on the server where there is no DOM, which lead to us spamming the terminal with false positive warnings.

So this skips the DOM validation if we reach the render root and thereby partially reverts #4043 . For SPAs this should work as the offending elements very likely have another DOM parent node anyway. For rendering into an existing DOM tree, this skips validation if we reach the render root eagerly. This seems like an ok tradeoff to make.

Fixes denoland/fresh#1773, fixes preactjs/preact-render-to-string#320

When Preact is rendering into a container in the middle of the page we
attempted to walk outside the render root via the DOM tree. Problem is
that that doesn't work on the server where there is no DOM, which
lead to us spamming the terminal with false positive warnings.

So this skips the DOM validation if we reach the render root.
@@ -79,7 +79,7 @@ describe('component stack', () => {
render(<Bar />, scratch);

let lines = getStack(errors).split('\n');
expect(lines[0].indexOf('td') > -1).to.equal(true);
expect(lines[0].indexOf('tr') > -1).to.equal(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates two warnings, which are both correct imo. The difference is that the order is only swapped because we do the validation based on the order in options.diffed which is the reverse of what we had before.

@github-actions
Copy link

Size Change: -109 B (0%)

Total Size: 57.2 kB

Filename Size Change
debug/dist/debug.js 3.5 kB -42 B (1%)
debug/dist/debug.module.js 3.5 kB -29 B (0%)
debug/dist/debug.umd.js 3.58 kB -38 B (1%)
ℹ️ View Unchanged
Filename Size Change
compat/dist/compat.js 3.95 kB 0 B
compat/dist/compat.module.js 3.87 kB 0 B
compat/dist/compat.umd.js 4.01 kB 0 B
devtools/dist/devtools.js 231 B 0 B
devtools/dist/devtools.module.js 240 B 0 B
devtools/dist/devtools.umd.js 315 B 0 B
dist/preact.js 4.42 kB 0 B
dist/preact.min.js 4.46 kB 0 B
dist/preact.min.module.js 4.45 kB 0 B
dist/preact.min.umd.js 4.48 kB 0 B
dist/preact.module.js 4.45 kB 0 B
dist/preact.umd.js 4.49 kB 0 B
hooks/dist/hooks.js 1.53 kB 0 B
hooks/dist/hooks.module.js 1.56 kB 0 B
hooks/dist/hooks.umd.js 1.62 kB 0 B
jsx-runtime/dist/jsxRuntime.js 360 B 0 B
jsx-runtime/dist/jsxRuntime.module.js 326 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 441 B 0 B
test-utils/dist/testUtils.js 453 B 0 B
test-utils/dist/testUtils.module.js 454 B 0 B
test-utils/dist/testUtils.umd.js 536 B 0 B

compressed-size-action

@coveralls
Copy link

Coverage Status

coverage: 99.282% (-0.01%) from 99.293% when pulling d19f87e on dom-validation into 19de3d9 on main.

@marvinhagemeister marvinhagemeister merged commit 8fb2f0d into main Oct 20, 2023
3 checks passed
@marvinhagemeister marvinhagemeister deleted the dom-validation branch October 20, 2023 09:54
@JoviDeCroock JoviDeCroock mentioned this pull request Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid nesting detection with preact/debug "Improper nesting" logged out unexpectedly
3 participants