Skip to content

metro-file-map: Remove TreeFS.getSerializableSnapshot - #2236

Open
robhogan wants to merge 2 commits into
mainfrom
pr2234
Open

robhogan wants to merge 2 commits into
mainfrom
pr2234

Conversation

@robhogan

@robhogan robhogan commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

#2219 added getSerializableState(), which returns the file system's own data, and moved the cache write onto it. This removes getSerializableSnapshot(), the deep copy it replaced, which nothing in Metro calls now.

Anyone calling getSerializableSnapshot() should migrate to getSerializableState(). Because it isn't a copy, it can drift as the file system changes unless it's consumed synchronously.

getSerializableState() is on MutableFileSystem rather than FileSystem, but the file system that FileMap.build() returns is a TreeFS, which implements it. A caller that holds on to the result across an await, or while the file map is watching, can copy it with structuredClone(), which copies at least as deeply as getSerializableSnapshot() did.

Though metro-file-map's API is private, I had a search around GitHub to make sure this won't break anyone - nothing outside Metro calls it, including RN and Expo.

Changelog: Internal

Test plan:
Needs a Meta import to check for internal callers.

@robhogan
robhogan added this pull request to stack #2109 November 16, 2026 18:39
@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 Nov 16, 2026
@robhogan
robhogan removed this pull request from stack #2109 November 16, 2026 22:09
@robhogan
robhogan added this pull request to stack #2241 November 16, 2026 22:10
@robhogan
robhogan requested review from huntie and vzaidman November 17, 2026 18:41
@robhogan
robhogan marked this pull request as ready for review November 17, 2026 18:44
@robhogan

Copy link
Copy Markdown
Collaborator Author

@vzaidman I'll merge the stack below this but leave this one for you - you may want to import it as I suspect there are internal callers that'll need migrating.

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: 67fbe6e · 7 commands run

This PR removes TreeFS.getSerializableSnapshot() and its #cloneTree helper, both now unused since the cache write moved to getSerializableState(). It updates API.md, the FileSystem and MutableFileSystem docs, and the tests to match. Nothing else in the repo calls the removed method; the plugin methods with the same name are a separate interface. Typecheck, the API snapshots and the TreeFS tests pass, and the new live-tree test fails if getSerializableState() returns a copy. The PR has no findings, and the only open question is internal callers, which the planned Meta import will show.

No findings.

Verified
  • ✅ yarn jest --no-watchman packages/metro-file-map/src/lib/__tests__/TreeFS-test.js — 332 passed
  • ❌ yarn jest --no-watchman packages/metro-file-map (head vs base) — Watchman, crawler-integration and FallbackWatcher tests fail in the sandbox on both head and base (head 13 failures, base 14). No failures related to the PR.
  • ✅ Mutation: make getSerializableState return structuredClone(root), then run TreeFS-test -t 'live tree' (failed as expected) — New test fails (2 failed, once per platform), so it catches a copy. TreeFS.js restored afterwards.
  • ✅ yarn typecheck
  • ✅ yarn verify-api-snapshots
  • ✅ yarn eslint on the changed files
  • ✅ Search the repo for getSerializableSnapshot and cloneTree — The only remaining hits are the FileMapPlugin method of the same name, which is a different interface.

Not run: Internal Meta callers can't be checked from OSS. Benchmarks weren't run because the PR only removes dead code.

Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call.

@robhogan robhogan added the Auto review: Good The Metro review bot found nothing to change at this head label Nov 20, 2026
Base automatically changed from pr2221 to main November 23, 2026 16:44
#2219 added `getSerializableState()`, which returns the file system's own data, and moved the cache write onto it. This removes `getSerializableSnapshot()`, the deep copy it replaced, which nothing in Metro calls now.

Anyone calling `getSerializableSnapshot()` should migrate to `getSerializableState()`. Because it isn't a copy, it can drift as the file system changes unless it's consumed synchronously.

`getSerializableState()` is on `MutableFileSystem` rather than `FileSystem`, but the file system that `FileMap.build()` returns is a `TreeFS`, which implements it. A caller that holds on to the result across an `await`, or while the file map is watching, can copy it with `structuredClone()`, which copies at least as deeply as `getSerializableSnapshot()` did.

Though `metro-file-map`'s API is private, I had a search around GitHub to make sure this won't break anyone - nothing outside Metro calls it, including RN and Expo.

Changelog: Internal

Test plan:
Needs a Meta import to check for internal callers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto review: Good The Metro review bot found nothing to change at this head CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. needs-meta-import

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants