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 nodeName to UPPERCASE in insertStylesheetIntoRoot #28255

Merged

Conversation

sweetliquid
Copy link
Contributor

@sweetliquid sweetliquid commented Feb 6, 2024

Summary

image

The condition node.nodeName === 'link' is always false, because node.nodeName is Uppercase in specification. And the condition node.nodeName === 'LINK' is unnecessary, because Fizz hoists tags when it's media attribute is "not all", whether it is a link or a style (line 36):

// Seed the precedence list with existing resources and collect hoistable style tags
const nodes = thisDocument.querySelectorAll(
'link[data-precedence],style[data-precedence]',
);
const styleTagsToHoist = [];
for (let i = 0; (node = nodes[i++]); ) {
if (node.getAttribute('media') === 'not all') {
styleTagsToHoist.push(node);
} else {
if (node.tagName === 'LINK') {
resourceMap.set(node.getAttribute('href'), node);
}
precedences.set(node.dataset['precedence'], (lastResource = node));
}
}

// Seed the precedence list with existing resources and collect hoistable style tags
const nodes = thisDocument.querySelectorAll(
'link[data-precedence],style[data-precedence]',
);
const styleTagsToHoist = [];
for (let i = 0; (node = nodes[i++]); ) {
if (node.getAttribute('media') === 'not all') {
styleTagsToHoist.push(node);
} else {
if (node.tagName === 'LINK') {
resourceMap.set(node.getAttribute('href'), node);
}
precedences.set(node.dataset['precedence'], (lastResource = node));
}
}

@facebook-github-bot
Copy link

Hi @sweetliquid!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@react-sizebot
Copy link

react-sizebot commented Feb 6, 2024

Comparing: 7039834...8b3cf21

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.66 kB 6.66 kB = 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 494.06 kB 494.06 kB = 88.22 kB 88.22 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 498.86 kB 498.86 kB = 88.93 kB 88.93 kB
facebook-www/ReactDOM-prod.classic.js = 591.22 kB 591.22 kB = 103.96 kB 103.96 kB
facebook-www/ReactDOM-prod.modern.js = 567.44 kB 567.44 kB = 100.36 kB 100.36 kB
test_utils/ReactAllWarnings.js Deleted 64.26 kB 0.00 kB Deleted 16.02 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 64.26 kB 0.00 kB Deleted 16.02 kB 0.00 kB

Generated by 🚫 dangerJS against 8b3cf21

@sweetliquid
Copy link
Contributor Author

If there are any problems, please guide me. Thanks!

@rickhanlonii
Copy link
Member

rickhanlonii commented Feb 11, 2024

@gnoff seems legit, and if not could we add a test that would fail this?

@sweetliquid sweetliquid force-pushed the fix/insertStylesheetIntoRoot-nodeName branch from 56b1460 to fca552b Compare March 6, 2024 10:23
@gnoff
Copy link
Collaborator

gnoff commented May 2, 2024

@sweetliquid the nodeName check is a shortcut to avoid the attribute lookup on link tags since it will likely be slower than just reading the node name. You're right thought that this is currently non-functional. But let's just fix it to uppercase so we can avoid the attr read for the majority of tags we process this way

@sweetliquid sweetliquid force-pushed the fix/insertStylesheetIntoRoot-nodeName branch from fca552b to 7c5c931 Compare May 7, 2024 14:37
@sweetliquid
Copy link
Contributor Author

@gnoff I've added back the nodeName check and fix it to uppercase, thanks for your explanation~

@sweetliquid sweetliquid force-pushed the fix/insertStylesheetIntoRoot-nodeName branch from 7c5c931 to 8b3cf21 Compare May 7, 2024 14:42
@sweetliquid sweetliquid changed the title Remove unnecessary check in insertStylesheetIntoRoot Fix nodeName comparison in insertStylesheetIntoRoot May 11, 2024
@sweetliquid sweetliquid changed the title Fix nodeName comparison in insertStylesheetIntoRoot Fix nodeName to UPPERCASE in insertStylesheetIntoRoot Jun 12, 2024
Copy link

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Sep 10, 2024
@sweetliquid
Copy link
Contributor Author

bump

@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Sep 14, 2024
@gnoff gnoff merged commit b75cc07 into facebook:main Sep 14, 2024
38 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 14, 2024
## Summary

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

<img width="518" alt="image"
src="https://github.com/facebook/react/assets/18693190/6d12df76-7dae-403b-b486-4940992abe8d">

The condition `node.nodeName === 'link'` is always `false`, because
`node.nodeName` is Uppercase in specification. And the condition
`node.nodeName === 'LINK'` is unnecessary, because Fizz hoists tags when
it's `media` attribute is `"not all"`, whether it is a `link` or a
`style` (line 36):

https://github.com/facebook/react/blob/18cbcbf783377c5a22277a63ae41af54504502e0/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetExternalRuntime.js#L30-L44

https://github.com/facebook/react/blob/18cbcbf783377c5a22277a63ae41af54504502e0/packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineSource.js#L30-L44

DiffTrain build for [b75cc07](b75cc07)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants