Repository navigation
Conversation
Fixes three regressions since 0.87.1: - #2064 drops cached files outside the roots on a warm start. Watchman lists a symlinked root's files under its real path, so they're all dropped, and imports into it fail until `--reset-cache`: ```js watchFolders: [path.resolve(__dirname, 'node_modules/my-linked-lib')] ``` Real paths of roots now count too (built-in crawlers only). - #1946 broke `hierarchicalLookup` through a symlink in a root to its parent: ``` app/monorepo -> .. (watchFolders: ['/repo']) import './monorepo/shared' -> ENOENT: /repo/app/mo/package.json ``` - #1677 stopped the Node crawler normalising roots: ``` roots: ['/proj/sub/'] -> 'sub//a.js' roots: ['/proj/other/../shared'] -> blockList for '/shared/dist' ignored ``` Changelog: Internal Test plan: - New unit tests for each, failing without this change. - Real Watchman, watch folder linked from `node_modules`: 3/3 files on a warm start (`main`: 1/3). - `hierarchicalLookup` fuzz, 50k lookups in random symlinked trees: every difference from before #1946 matches a real-path model.
vzaidman
approved these changes
Oct 26, 2026
robhogan
added a commit
to expo/expo
that referenced
this pull request
Nov 24, 2026
# Why Metro 0.88 calls two `FileMap` methods the fork doesn't have. `addRoot(dir)` adds `metro-runtime` and its `@babel/runtime` as roots once the file map is built, so that `emptyModulePath`'s new default, `metro:runtime/modules/empty-module`, is in the file map wherever `metro-runtime` is installed. `getRoots()` is called for every asset transform and URL it maps. Without them, `ready()` fails on the first, and the first asset throws on the second. Nothing else in the file map contract changed in 0.88. | Upstream | What | Expo | |---|---|---| | react/metro#2064 | Add `FileMap.addRoot` | - | | react/metro#2020 | Add `FileMap.getRoots` | - | | react/metro#2093 | Fix root normalization and symlinked roots in `addRoot` | - | # How This ports them method by method from Metro 0.88.0, which upstream `main` hasn't changed since. `addRoot` resolves symlinks in the given path, does nothing for a root that is already a root or within one, and otherwise watches the root, then crawls it with the node crawler (`subpath` set), applies the result as a startup crawl does, and emits one `'change'` for its files. `Watcher.watchRoot` starts a backend for the root, confirming its watch as #54143 does for the initial roots. Added roots aren't persisted, so a later start drops their files from the cache, plugins included. `#changeQueue` becomes a field, as upstream, so that an added root's crawl is serialized with watcher events. The on-demand filesystem needs one fork-only change. Resolving the new root's symlinks is a lookup, which fills the root's top level on demand before it's crawled. Those files then compare as unchanged in the crawl, so plugins and the `'change'` event never see them, and later misses under the root still read the disk. `TreeFS.setRoots` (upstream's name on robhogan/is-mapped) is called whenever the roots change. It stops the on-demand filesystem filling under a new root and drops what it filled there, without notifying listeners, which were never told of those files, so the crawl reports them. # Test Plan - Unit tests (810 passed, 2 skipped). - Upstream's `addRoot-test` is ported, with fork-only cases for the on-demand filesystem: files it filled under a new root are reported as added, it doesn't fill paths under an added root, and it still fills paths outside every root. The first two fail without `setRoots`. - One ported case is skipped: a configured root given through a symlink keeps its files in a start from the cache. The fork saves only files under the roots as given, so Watchman's listing of such a root under its real path isn't saved. This predates this change, and fixing it changes what the on-demand filesystem fills, so it's left for a follow-up.
robhogan
added a commit
to expo/expo
that referenced
this pull request
Nov 25, 2026
# Why Metro 0.88 calls two `FileMap` methods the fork doesn't have, which is the last thing blocking an update. `addRoot(dir)` is used to add `metro-runtime` and its `@babel/runtime` as roots once the file map is built, so that `emptyModulePath`'s new default, `metro:runtime/modules/empty-module`, is guaranteed to be the file map wherever `metro-runtime` is installed, and similarly `metro:babel-runtime` (`babel-plugin-transform-runtime`) resolves to a known-watched, known-version library (Expo currently has an override for that anyway, which we could drop). `getRoots()` is called for every asset transform and URL it maps. Without them, `ready()` fails on the first, and the first asset throws on the second. Nothing else in the file map contract changed in 0.88. Neither is observable in Expo, which has its own asset handling and overrides for the two `metro-runtime` paths, but `addRoot` is planned to become load bearing as the upstream version of the on-demand file system. | Upstream | What | Expo | |---|---|---| | react/metro#2064 | Add `FileMap.addRoot` | - | | react/metro#2020 | Add `FileMap.getRoots` | - | | react/metro#2093 | Fix root normalization and symlinked roots in `addRoot` | - | # How This ports them method by method from Metro 0.88.0, which upstream `main` hasn't changed since. The on-demand filesystem needs one fork-only change - `TreeFS.setRoots` is called whenever the roots change, to keep the on-demand file system from populating or persisting a new watched root. Metro's crawler reports changes from added roots. # Test Plan - Upstream's `addRoot-test` is ported, with fork-only cases for the on-demand filesystem: files it filled under a new root are reported as added, it doesn't fill paths under an added root, and it still fills paths outside every root. The first two fail without `setRoots`. - One ported case is skipped: a configured root given through a symlink keeps its files in a start from the cache. The fork saves only files under the roots as given, so Watchman's listing of such a root under its real path isn't saved. This predates this change, and fixing it changes what the on-demand filesystem fills, so it's left for a follow-up.
robhogan
added a commit
to expo/expo
that referenced
this pull request
Nov 25, 2026
# Why Metro 0.88 calls two `FileMap` methods the fork doesn't have, which is the last thing blocking an update. `addRoot(dir)` is used to add `metro-runtime` and its `@babel/runtime` as roots once the file map is built, so that `emptyModulePath`'s new default, `metro:runtime/modules/empty-module`, is guaranteed to be the file map wherever `metro-runtime` is installed, and similarly `metro:babel-runtime` (`babel-plugin-transform-runtime`) resolves to a known-watched, known-version library (Expo currently has an override for that anyway, which we could drop). `getRoots()` is called for every asset transform and URL it maps. Without them, `ready()` fails on the first, and the first asset throws on the second. Nothing else in the file map contract changed in 0.88. Neither is observable in Expo, which has its own asset handling and overrides for the two `metro-runtime` paths, but `addRoot` is planned to become load bearing as the upstream version of the on-demand file system. | Upstream | What | Expo | |---|---|---| | react/metro#2064 | Add `FileMap.addRoot` | - | | react/metro#2020 | Add `FileMap.getRoots` | - | | react/metro#2093 | Fix root normalization and symlinked roots in `addRoot` | - | # How This ports them method by method from Metro 0.88.0, which upstream `main` hasn't changed since. The on-demand filesystem needs one fork-only change - `TreeFS.setRoots` is called whenever the roots change, to keep the on-demand file system from populating or persisting a new watched root. Metro's crawler reports changes from added roots. # Test Plan - Upstream's `addRoot-test` is ported, with fork-only cases for the on-demand filesystem: files it filled under a new root are reported as added, it doesn't fill paths under an added root, and it still fills paths outside every root. The first two fail without `setRoots`. - One ported case is skipped: a configured root given through a symlink keeps its files in a start from the cache. The fork saves only files under the roots as given, so Watchman's listing of such a root under its real path isn't saved. This predates this change, and fixing it changes what the on-demand filesystem fills, so it's left for a follow-up. (cherry picked from commit 6953e2a)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes three edge case regressions since 0.87.1:
watchFoldersto non-real paths. Watchman lists a symlinked root's files under its real path, so they're all dropped, and imports into it fail until--reset-cache:hierarchicalLookupthrough a symlink in a root to its parent:Changelog: Internal
Test plan:
node_modules: 3/3 files on a warm start (main: 1/3).hierarchicalLookupfuzz, 50k lookups in random symlinked trees: every difference from before metro-file-map: Check hierarchicalLookup candidates from their own nodes #1946 matches a real-path model.