Skip to content

Commit

Permalink
fix: bind scope to null to prevent issues with inline requires (#2972)
Browse files Browse the repository at this point in the history
## Description

- I've identified an issue with Metro's inlineRequires + experimentalImportSupport while building tree shaking support for Expo CLI. This issue causes an invalid invocation to be thrown because the scope of the build-in functions is not correct.
- More info can be found here https://github.com/EvanBacon/inline-requires-issue

<!--
Description and motivation for this PR.

Include 'Fixes #<number>' if this is fixing some issue.
-->

## Test plan

- In my [repro](https://github.com/EvanBacon/inline-requires-issue) the bindings no longer throw. I've raised the issue with Metro team so we can create a system-wide fix, but this should prevent any issues in the meantime.
  • Loading branch information
EvanBacon committed Jul 2, 2024
1 parent 5f1451a commit de0e6bd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ghQueueMicrotask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// We check for typeof requestAnimationFrame because of SSR
export const ghQueueMicrotask =
typeof requestAnimationFrame === 'function'
? requestAnimationFrame
: queueMicrotask;
? // Functions are bound to null to avoid issues with scope when using Metro inline requires.
requestAnimationFrame.bind(null)
: queueMicrotask.bind(null);

0 comments on commit de0e6bd

Please sign in to comment.