react / react/metro

creating isolated bundles

Open
#1,618 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

I’m generating multiple bundles with Metro to load later from the native side.
The problem is that the bundles aren’t isolated. Metro injects variables at the top of each bundle, and those variables get hoisted when the bundles are loaded, potentially overwriting each other. For example, the globalPrefix option in the Metro transformer is supposed to differentiate global symbols per bundle, but it itself gets hoisted and pollutes the global scope, so all bundles end up sharing the same globalPrefix.

Is there a way to force Metro to isolate bundles—for example, by wrapping each bundle in an IIFE? I tried post-processing the bundles manually, but that breaks the sourcemaps.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining Metro's transformer handling of globalPrefix and bundle generation; the issue provides no file or test entry point. Compare how multiple bundles are loaded from the native side and how sourcemaps are preserved. Done means bundles remain isolated without globalPrefix collisions and sourcemaps continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.