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

[compiler] Fix FBT whitespace handling again (again (again)) #30451

Merged
merged 5 commits into from
Jul 29, 2024

Conversation

mofeiZ
Copy link
Contributor

@mofeiZ mofeiZ commented Jul 24, 2024

Stack from ghstack (oldest at bottom):

Fbt whitespace rules apply to their entire jsx subtrees, not just direct children. Since fbt transform runs after react-compiler, let's just retain all whitespace as is.

Tested internally by diffing fbt compilation tables (with and without react-compiler in the pipeline). See results here https://fburl.com/diff/t43dopfg. Note there are no differences except for 2 edge cases in which babel-transform-fbt fails to dedupe some table entries. This can help us be more confident that this fix covers all edge cases (without adding all permutations of fbt whitespace / elements to test fixtures)

Copy link

vercel bot commented Jul 24, 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 Jul 26, 2024 9:42pm

mofeiZ added a commit that referenced this pull request Jul 24, 2024
ghstack-source-id: a24a48e0a42e243b6c72481cd82cee819ccea309
Pull Request resolved: #30451
@facebook-github-bot facebook-github-bot added the React Core Team Opened by a member of the React Core Team label Jul 24, 2024
mofeiZ added a commit that referenced this pull request Jul 24, 2024
ghstack-source-id: ca54bce9346508e19680bd3b09f98e26fa059f3d
Pull Request resolved: #30451
@mofeiZ mofeiZ marked this pull request as ready for review July 24, 2024 21:44
@mofeiZ mofeiZ marked this pull request as draft July 24, 2024 22:13
Fbt whitespace rules apply to their entire jsx subtrees, not just direct children

(testing internally in progress)


[ghstack-poisoned]
mofeiZ added a commit that referenced this pull request Jul 24, 2024
ghstack-source-id: 452185559d61e6742102c9945fe2c56eb5d69802
Pull Request resolved: #30451
Copy link
Contributor

@josephsavona josephsavona left a comment

Choose a reason for hiding this comment

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

Overall approach makes sense! Nice find! I’ll let other review more thoroughly

tag.kind === 'BuiltinTag' &&
(tag.name === 'fbt' || tag.name === 'fbs')
) {
true &&
Copy link
Contributor

Choose a reason for hiding this comment

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

true && - remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, removed!

Copy link
Contributor

@mvitousek mvitousek left a comment

Choose a reason for hiding this comment

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

Looks very reasonable to me! What a messy transform lol.

* whitespace as is.
* https://github.com/facebook/fbt/blob/0b4e0d13c30bffd0daa2a75715d606e3587b4e40/packages/babel-plugin-fbt/src/FbtUtil.js#L76-L87
*/
// text = exprPath.node.value.replace(/[^\S\u00A0]+/g, ' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

Cleanup?

* Increment fbt counter before traversing into children, as whitespace
* in jsx text is handled differently for fbt subtrees.
*/
isFbt && builder.fbtDepth++;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe include in the isFbt conditional block directly above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I figured this might be cleaner (keeping the increment / decrement next the recursive call), but I don't have strong opinions here. Happy to fix forward if you think that's a cleaner pattern

Copy link
Contributor

Choose a reason for hiding this comment

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

No strong opinions here :)

Fbt whitespace rules apply to their entire jsx subtrees, not just direct children

(testing internally in progress)


[ghstack-poisoned]
Fbt whitespace rules apply to their entire jsx subtrees, not just direct children. Since fbt transform runs after react-compiler, let's just retain all whitespace as is.

Tested internally by diffing fbt compilation tables (with and without react-compiler in the pipeline). See results here https://fburl.com/diff/t43dopfg. Note there are no differences except for 2 edge cases in which `babel-transform-fbt` fails to dedupe some table entries.


[ghstack-poisoned]
@mofeiZ mofeiZ marked this pull request as ready for review July 26, 2024 21:37
@mofeiZ mofeiZ merged commit c11b88c into gh/mofeiZ/16/base Jul 29, 2024
19 checks passed
mofeiZ added a commit that referenced this pull request Jul 29, 2024
ghstack-source-id: 00a86e41cfb8a6fb56b7fcd811740d1d9b89a611
Pull Request resolved: #30451
@mofeiZ mofeiZ deleted the gh/mofeiZ/16/head branch July 29, 2024 17:18
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