Skip to content

fix: Metro inline-plugin doesn't support relative ES imports of Platform and it cause dead-code in production#57121

Closed
retyui wants to merge 1 commit into
react:mainfrom
retyui:feat/retyui/no-dead-code
Closed

fix: Metro inline-plugin doesn't support relative ES imports of Platform and it cause dead-code in production#57121
retyui wants to merge 1 commit into
react:mainfrom
retyui:feat/retyui/no-dead-code

Conversation

@retyui

@retyui retyui commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary:

Metro inline-plugin doesn't work when an Platform has relative ES import

// source code
Platform.OS === 'android' 

// expected (when build for ios)
"ios" === "android" // <-- always false, so deadcode elimination algorithm can remove the code

// actual
"android" === r.default.OS

metro has own PR: react/metro#1692 (comment) but no lock it will be merged soon I think

Changelog:

[GENERAL] [FIXED] - No dead-code in production for internal usages of Platform

Test Plan:

Before:

Screenshot 2026-04-20 at 17 45 12

After

Screenshot 2026-06-09 at 10 36 53

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 9, 2026
@facebook-github-tools facebook-github-tools Bot added p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jun 9, 2026
@rubennorte

Copy link
Copy Markdown
Contributor

Could we please update the inline plugin instead of reverting all these usages to require calls? I'm afraid this isn't very idiomatic, won't scale well and a lot of use cases will be reverted over time organically.

@retyui

retyui commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@rubennorte As I mentioned in the description an inline-plugin has own PR: react/metro#1692 (comment) but no luck it will be merged

so to devilry a simple dead-code elimination trick for all devs in the world this PR was created and hope will be available in the next release of RN

@javache

javache commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The right direction here is to fix the issue in react/metro#1692 not the import legacy requires in the react-native codebase.

@javache javache closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants