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

[fizz] fix empty string href double warning #31783

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rickhanlonii
Copy link
Member

@rickhanlonii rickhanlonii commented Dec 14, 2024

I think this is the suggested change from #31765 (comment)

But no tests fail and I'm not sure how to test it? Seems sus.

Also seems like the removeAttribute here should be changed?

if (
value === '' &&
// <a href=""> is fine for "reload" links.
!(tag === 'a' && key === 'href')
) {
if (__DEV__) {
if (key === 'src') {
console.error(
'An empty string ("") was passed to the %s attribute. ' +
'This may cause the browser to download the whole page again over the network. ' +
'To fix this, either do not render the element at all ' +
'or pass null to %s instead of an empty string.',
key,
key,
);
} else {
console.error(
'An empty string ("") was passed to the %s attribute. ' +
'To fix this, either do not render the element at all ' +
'or pass null to %s instead of an empty string.',
key,
key,
);
}
}
domElement.removeAttribute(key);
break;
}

Copy link

vercel bot commented Dec 14, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 15, 2024 8:30pm

@react-sizebot
Copy link

react-sizebot commented Dec 14, 2024

Comparing: e06c72f...3e7761c

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.03% 510.76 kB 510.90 kB +0.02% 91.36 kB 91.38 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.03% 515.55 kB 515.69 kB +0.02% 92.17 kB 92.19 kB
facebook-www/ReactDOM-prod.classic.js +0.02% 594.69 kB 594.83 kB +0.01% 104.93 kB 104.94 kB
facebook-www/ReactDOM-prod.modern.js +0.02% 584.96 kB 585.10 kB +0.02% 103.37 kB 103.39 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 6052c9a

@sebmarkbage
Copy link
Collaborator

It's probably expressible with the server integration tests somehow. But you can test it in /fixture/ssr which actually has this error already.

@rickhanlonii
Copy link
Member Author

@sebmarkbage see my comment in the description about the removeAttribute in setProp

@rickhanlonii rickhanlonii changed the title [wip] fix empty string href double warning [fizz] fix empty string href double warning Dec 14, 2024
Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

Also seems like the removeAttribute here should be changed?

No I think that's correct because the server also omits the attribute.

@rickhanlonii
Copy link
Member Author

@sebmarkbage I repro'd in the fixture and this doesn't fix it (or I'm missing a feature flag or something).

What happens today (same on main and this PR, I added logs, and don't think this branch is actually getting hit):

image

I'm confused what the behavior you're expecting is? The server and the client both strip the attribute, but the prop is still empty string. So canHydrateInstance is going to return null if they mismatch because of the check here:

element.getAttribute('href') !==
(anyProps.href == null ? null : anyProps.href) ||

I'll push a commit that fixes this so you can see the difference.

@rickhanlonii
Copy link
Member Author

Ok latest commit fixes it so that empty string hydrates as null, with tests, and this is the result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants