Skip to content

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)

@vercel
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
@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
@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
Copy link
Member

@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
Member

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
mofeiZ added a commit that referenced this pull request Jul 29, 2024
@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