Skip to content

Fix metro-runtime's require system getter checks for ESM live bindings#1575

Closed
kitten wants to merge 1 commit into
react:mainfrom
kitten:@kitten/fix/esm-live-binding-fast-refresh
Closed

Fix metro-runtime's require system getter checks for ESM live bindings#1575
kitten wants to merge 1 commit into
react:mainfrom
kitten:@kitten/fix/esm-live-binding-fast-refresh

Conversation

@kitten

@kitten kitten commented Sep 10, 2025

Copy link
Copy Markdown
Contributor

Summary

In Expo, we're about to introduce ESM live bindings. We noticed that the metro-runtime performs checks for getters to skip over for Fast Refresh checks, likely because of CommonJS modules that may be doing module.exports = { get() { throw new Error() } } and the likes.

This check is redundant on ESModule-transpiled modules, since we know that getters that were transpiled in for ESM exports are safe to access.

For example, we may have entries such as:

Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, 'default', {
  enumerable: true,
  get: function() {
    return _default;
  },
});

See: expo/expo#39525

Changelog: [Fix] Fix metro-runtime's fast refresh checks to not skip over getters for ES modules

Test plan

@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 Sep 10, 2025
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 10, 2025
@kitten kitten force-pushed the @kitten/fix/esm-live-binding-fast-refresh branch from ba85a86 to 978d484 Compare September 10, 2025 13:40
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@robhogan has imported this pull request. If you are a Meta employee, you can view this in D82119709.

@robhogan robhogan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good - thanks

There's a small edge case here where a module may export a dangerous getter and be an __esModule, because we allow mixed syntax:

module.exports = {
  get danger() {
    throw 'problems';
  }
};
export default 'spanner';

...but I think we can live with that - nobody should be writing it. You might want to disallow hybrid CJS/ESM syntax on your end to be sure.

@kitten

kitten commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

Current thinking is to leave it on until we find a library that relies on mixed ESM+CJS that causes this to break 👍 Mostly because we're curious if we need to actively prohibit this

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@robhogan merged this pull request in 076c3b4.

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. Merged 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