Skip to content

[compiler][ez] Option to bail out on blocklisted imports #30643

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

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

mofeiZ
Copy link
Contributor

@mofeiZ mofeiZ commented Aug 8, 2024

Copy link

vercel bot commented Aug 8, 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 Aug 8, 2024 10:50pm

mofeiZ added a commit that referenced this pull request Aug 8, 2024
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Aug 8, 2024
import {getOrInsertDefault} from '../Utils/utils';

export function validateRestrictedImports(
path: NodePath<t.Program>,
Copy link
Member

Choose a reason for hiding this comment

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

Hmm we should be able to use LoadGlobal’s binding information to see if a dangerous import is actually used in a particular component/hook.

Is there a motivating use-case to check at the program level or was that just an easy way to do the check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@josephsavona My understanding is that there were a few cases when we wanted to bail-out on higher-level component logic. I also thought about bailing out on LoadGlobal (NonLocalBinding.module), but another issue is that it doesn't follow aliasing or data flow (e.g. I may alias or do a PropertyLoad off of an import).

From my understanding, the modules we want to bail out on are pretty rarely imported (~20 matches internally). They are also React-related (e.g. createContainer or exporting a dangerous hook function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so far, we were able to avoid using this (it's really not a scalable option) by relying on Flow + compiler bailouts. For now, the restricted modules aren't used enough for false positives to matter -- false negatives on the other hand might be annoying to debug.

We can re-evaluate / rewrite if our rollout strategy changes

@mofeiZ mofeiZ marked this pull request as ready for review August 8, 2024 22:26
mofeiZ added a commit that referenced this pull request Aug 8, 2024
…ng logic in Program"

---
Drive-by cleanup when writing #30643


[ghstack-poisoned]
mofeiZ added a commit that referenced this pull request Aug 8, 2024
…ram"

---
Drive-by cleanup when writing #30643


[ghstack-poisoned]
mofeiZ added a commit that referenced this pull request Aug 8, 2024
mofeiZ added a commit that referenced this pull request Aug 8, 2024
@mofeiZ mofeiZ merged commit b091572 into gh/mofeiZ/16/base Aug 9, 2024
19 checks passed
mofeiZ added a commit that referenced this pull request Aug 9, 2024
@mofeiZ mofeiZ deleted the gh/mofeiZ/16/head branch August 9, 2024 16:10
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.

3 participants