Skip to content

DeltaCalculator: Apply changes made during a (failed or successful) build on top - #2007

Merged
robhogan merged 2 commits into
react:mainfrom
YevheniiKotyrlo:fix/delta-calculator-changes-during-failed-build
Oct 7, 2026
Merged

robhogan merged 2 commits into
react:mainfrom
YevheniiKotyrlo:fix/delta-calculator-changes-during-failed-build

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

When a delta build fails, getDelta puts back the change sets it took as a plain union with the changes that arrived during the build. A file that changed both before and during the failed build ends up in two sets:

  • deleted, then recreated: in _addedFiles and _deletedFiles, so the next delta skips the file and the client keeps the old module;
  • modified, then deleted: in _modifiedFiles and _deletedFiles, so the next delta traverses a deleted file.

The failing build is often the one the deletion started, an import that no longer resolves, so the window is that build's whole duration: 11.7 s where I hit it, an iPad loading from Metro on Windows.

The fix restores the taken sets and replays the later changes on top of them through the transitions _handleMultipleFileChanges uses, extracted as #markAdded, #markModified and #markDeleted.

(Added by @robhogan: Also cover the related case where a file is deleted and re-added during a successful build, so that we remember to treat it as modified for the next build)

Changelog: [Fix] Track files changed during a delta build correctly, so the next delta rebuilds a recreated file and skips a deleted one

Test plan

  • Two DeltaCalculator-test.js cases, run for posix and win32 paths: a file deleted and recreated during a failed build is traversed by the next delta, and a file modified and deleted during one is not. All four fail on main and pass with the fix.
  • yarn typecheck, typecheck-ts, lint, format-check, build, test-smoke and test-coverage (151 suites, 2760 passed, 26 skipped).
  • On the iPad, deleting a directory the screen imports and recreating it while the failed build runs: on main the next update carried 7 modules and none of the 20 recreated ones, and the screen kept the old text; with the fix it carries all 20 and the screen updates.

When a delta build fails, getDelta put back the change sets it took as a
plain union with the changes that arrived during the build. A file deleted
before the build and recreated during it then sat in both the added and the
deleted set and was skipped by the next delta, so the client kept the old
module; a file modified before the build and deleted during it was
traversed after its deletion.

The taken sets are now restored as the base, and the later changes are
replayed on top through the transitions the change handler uses.
@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 Oct 2, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 2, 2026
A file deleted before a build and recreated before its importer re-resolves it leaves the build green with the graph still holding the old module. The recreated file then only ever sits in the added set, which nothing traverses, so the client keeps stale code until the file changes again.

An added file that already has a module in the graph can only be one the graph never saw deleted, so it is now treated as modified and revisited on the next delta. This covers the successful build as well as the failed one.
@robhogan robhogan changed the title DeltaCalculator: Apply changes made during a failed build on top DeltaCalculator: Apply changes made during a (failed or successful) build on top Oct 6, 2026

@robhogan robhogan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks again!

@robhogan
robhogan merged commit 60903e6 into react:main Oct 7, 2026
16 checks passed
robhogan added a commit that referenced this pull request Oct 21, 2026
Summary:
Publish Metro 0.87.2 from `main`.

Changelog: [Internal]

Test plan:
```
node scripts/updateVersion.js 0.87.2
sl diff --stat
```

Only the 17 `packages/*/package.json` manifests change, and every `0.87.1` reference is replaced.

Draft release notes (from the 95 commits in v0.87.1...main - internal-only changes omitted):

```
 - **[Feature]**: Add a built-in `metro:runtime/*` specifier, resolvable from any importer, eg for `transformer.asyncRequireModulePath` (#2083 by @robhogan)
 - **[Feature]**: When `transformer.enableBabelRuntime` is `true`, pass Metro's own `@babel/runtime` (`metro:babel-runtime`) and its installed version to Babel presets via caller data (#1957 by @robhogan)
 - **[Fix]**: Resolver: Fix stale resolutions after adding a nearer `package.json` or retargeting a symlinked directory, which previously needed a restart (#1948 by @robhogan)
 - **[Fix]**: Resolver: Packages and directories named with an asset extension (eg `lodash.zip`) resolve as modules rather than failing as assets (#2055 by @robhogan)
 - **[Fix]**: Resolver: Fall through to parent conditions when a nested `"exports"` or `"imports"` condition has no matching target (#2074 by @maximilliangrand)
 - **[Fix]**: Resolver: An exact `"exports"` or `"imports"` subpath with a `null` or unmatched target no longer resolves through a less specific subpath pattern (#1987 by @kwy404)
 - **[Fix]**: Use indexed watch folder paths (`[metro-watchFolders]/N/`) for assets outside `projectRoot` (#1892 by @robhogan)
 - **[Fix]**: Fix `/[metro-project]/` and `/[metro-watchFolders]/` bundle serving on Windows (#2015 by @motiz88)
 - **[Fix]**: Prevent HMR crash on `[metro-watchFolders]` or `[metro-project]` URLs (#2017 by @motiz88)
 - **[Fix]**: Remove erroneous `[metro-project]` and `[metro-watchFolders]` resolution of entry points from the API and CLI (#2030 by @motiz88)
 - **[Fix]**: Fix backslashes in async bundle paths on Windows (`includeAsyncPaths`) (#1938 by @robhogan)
 - **[Fix]**: Fix stale modules on the client when a file is deleted and recreated during a build, or changes during a build that fails (#2007 by @YevheniiKotyrlo)
 - **[Fix]**: Fix files created or modified while Metro starts up being missed until restart (#2054 by @cpruijsen)
 - **[Fix]**: Fix watch mode losing files when a directory replaces a file or symlink, eg when unlinking a package (#2009 by @robhogan)
 - **[Fix]**: Fix the fallback (Linux/Windows) watcher hanging on stop, and missing changes in a replaced directory, after a watch error (#1967 by @robhogan)
 - **[Fix]**: Fix the fallback watcher missing changes when a directory changes faster than Windows can report (#1967 by @robhogan)
 - **[Fix]**: Close the watch handles of a deleted directory and every directory under it in `FallbackWatcher`, which kept the process busy on Windows (#2004 by @YevheniiKotyrlo)
 - **[Fix]**: `metro-file-map`: Fix removing a non-active duplicate mock changing which mock is active (#1756 by @durvesh1992)
 - **[Fix]**: Propagate transformer initialisation errors from `Bundler` (#1854 by @Boulea7)
 - **[Fix]**: Release transform workers and file watchers when Metro fails to initialise (#1963 by @robhogan)
 - **[Fix]**: Ignore hyphenated and namespaced SVG attributes (eg `stroke-width`) when reading SVG asset dimensions (#1972 by @GabrielDumbrava)
 - **[Fix]**: Fix generated positions when iterating the mappings of indexed source maps, eg in `composeSourceMaps` (#1976 by @kwy404)
 - **[Fix]**: `composeSourceMaps` keeps every mapping at a generated column that the last map maps more than once (#1981 by @robhogan)
 - **[Fix]**: Source maps no longer lose lines after a gap of more than about two million unmapped generated lines (#1983 by @robhogan)
 - **[Fix]**: `metro-symbolicate` no longer fails on stack frames with no source position, such as `[native code]:0:0` in crash reporter output (#1891 by @robhogan)
 - **[Fix]**: Fix `metro-symbolicate` parsing of stack frames with Windows absolute paths (#1939 by @robhogan)
 - **[Performance]**: `metro-source-map`: Faster `Consumer` decoding and position lookups, and `composeSourceMaps` encodes its output directly - 3.2x faster composition of a bundle map with its Hermes map, using 15% less memory (#1978, #1979, #1980, #1983 by @robhogan)
 - **[Performance]**: Resolver: Ask for the package of a directory once for all extension candidates, and check `hierarchicalLookup` candidates from their own file map nodes. First-pass resolution is 35% faster (172ms -> 113ms on a mid-size RN app), net of a ~3% first-build cost from dropping `PackageCache`'s closest-package memo, which also cuts the resolver's retained heap by 37% (#1945, #1946, #1948 by @robhogan)
 - **[Performance]**: 33% faster non-Watchman file system crawl on startup (#1677 by @kitten)
 - **[Deprecated]**: `server.enhanceMiddleware` logs a deprecation warning when set to anything other than its default. Use `server.unstable_middleware` or `server.unstable_priorityMiddleware` (#2031 by @vzaidman)
 - **[Deprecated]**: `runServer`'s `unstable_extraMiddleware` option. Use `unstable_priorityMiddleware`, which runs the same middleware in the same place (#2031 by @vzaidman)
 - **[Deprecated]**: String values of `transformer.enableBabelRuntime` (use `true`) (#1957 by @robhogan)
 - **[Types]**: Add TypeScript definitions for `metro-runtime` modules, and generate (rather than hand-maintain) types for `metro-file-map` workers (#1996 by @robhogan)

> NOTE: Experimental features are not covered by semver and can change at any time.

 - **[Experimental]**: Add `server.unstable_middleware` and `server.unstable_priorityMiddleware` config options, and `runServer` options of the same names, to add middleware after and before Metro's own. `mergeConfig` combines them from both configs: a later config's `unstable_middleware` runs last and its `unstable_priorityMiddleware` runs first (#2031 by @vzaidman)
 - **[Experimental]**: Add `server.unstable_onServerCreated` config option and `runServer` option of the same name, called with Metro's server instance before the HTTP server listens (#2031 by @vzaidman)
 - **[Experimental]**: Fix mismatched asset paths in (release) builds under `unstable_serverRoot`, make them always relative to `projectRoot` (#1917 by @robhogan)

 **Full Changelog**: v0.87.1...v0.87.2
```
robhogan added a commit that referenced this pull request Oct 21, 2026
Summary:
Publish Metro 0.87.2 from `main`.

Changelog: [Internal]

Test plan:
```
node scripts/updateVersion.js 0.87.2
sl diff --stat
```

Only the 17 `packages/*/package.json` manifests change, and every `0.87.1` reference is replaced.

Draft release notes (from the 95 commits in v0.87.1...main - internal-only changes omitted):

```
 - **[Feature]**: Add a built-in `metro:runtime/*` specifier, resolvable from any importer, eg for `transformer.asyncRequireModulePath` (#2083 by @robhogan)
 - **[Feature]**: When `transformer.enableBabelRuntime` is `true`, pass Metro's own `@babel/runtime` (`metro:babel-runtime`) and its installed version to Babel presets via caller data (#1957 by @robhogan)
 - **[Fix]**: Resolver: Fix stale resolutions after adding a nearer `package.json` or retargeting a symlinked directory, which previously needed a restart (#1948 by @robhogan)
 - **[Fix]**: Resolver: Packages and directories named with an asset extension (eg `lodash.zip`) resolve as modules rather than failing as assets (#2055 by @robhogan)
 - **[Fix]**: Resolver: Fall through to parent conditions when a nested `"exports"` or `"imports"` condition has no matching target (#2074 by @maximilliangrand)
 - **[Fix]**: Resolver: An exact `"exports"` or `"imports"` subpath with a `null` or unmatched target no longer resolves through a less specific subpath pattern (#1987 by @kwy404)
 - **[Fix]**: Use indexed watch folder paths (`[metro-watchFolders]/N/`) for assets outside `projectRoot` (#1892 by @robhogan)
 - **[Fix]**: Fix `/[metro-project]/` and `/[metro-watchFolders]/` bundle serving on Windows (#2015 by @motiz88)
 - **[Fix]**: Prevent HMR crash on `[metro-watchFolders]` or `[metro-project]` URLs (#2017 by @motiz88)
 - **[Fix]**: Remove erroneous `[metro-project]` and `[metro-watchFolders]` resolution of entry points from the API and CLI (#2030 by @motiz88)
 - **[Fix]**: Fix backslashes in async bundle paths on Windows (`includeAsyncPaths`) (#1938 by @robhogan)
 - **[Fix]**: Fix stale modules on the client when a file is deleted and recreated during a build, or changes during a build that fails (#2007 by @YevheniiKotyrlo)
 - **[Fix]**: Fix files created or modified while Metro starts up being missed until restart (#2054 by @cpruijsen)
 - **[Fix]**: Fix watch mode losing files when a directory replaces a file or symlink, eg when unlinking a package (#2009 by @robhogan)
 - **[Fix]**: Fix the fallback (Linux/Windows) watcher hanging on stop, and missing changes in a replaced directory, after a watch error (#1967 by @robhogan)
 - **[Fix]**: Fix the fallback watcher missing changes when a directory changes faster than Windows can report (#1967 by @robhogan)
 - **[Fix]**: Close the watch handles of a deleted directory and every directory under it in `FallbackWatcher`, which kept the process busy on Windows (#2004 by @YevheniiKotyrlo)
 - **[Fix]**: `metro-file-map`: Fix removing a non-active duplicate mock changing which mock is active (#1756 by @durvesh1992)
 - **[Fix]**: Propagate transformer initialisation errors from `Bundler` (#1854 by @Boulea7)
 - **[Fix]**: Release transform workers and file watchers when Metro fails to initialise (#1963 by @robhogan)
 - **[Fix]**: Ignore hyphenated and namespaced SVG attributes (eg `stroke-width`) when reading SVG asset dimensions (#1972 by @GabrielDumbrava)
 - **[Fix]**: Fix generated positions when iterating the mappings of indexed source maps, eg in `composeSourceMaps` (#1976 by @kwy404)
 - **[Fix]**: `composeSourceMaps` keeps every mapping at a generated column that the last map maps more than once (#1981 by @robhogan)
 - **[Fix]**: Source maps no longer lose lines after a gap of more than about two million unmapped generated lines (#1983 by @robhogan)
 - **[Fix]**: `metro-symbolicate` no longer fails on stack frames with no source position, such as `[native code]:0:0` in crash reporter output (#1891 by @robhogan)
 - **[Fix]**: Fix `metro-symbolicate` parsing of stack frames with Windows absolute paths (#1939 by @robhogan)
 - **[Performance]**: `metro-source-map`: Faster `Consumer` decoding and position lookups, and `composeSourceMaps` encodes its output directly - ~3.2x faster composition of a bundle map with its Hermes map, using ~15% less memory (#1978, #1979, #1980, #1983 by @robhogan)
 - **[Performance]**: Resolver: Ask for the package of a directory once for all extension candidates, and check `hierarchicalLookup` candidates from their own file map nodes. First-pass resolution is ~35% faster, net of a ~3% first-build cost from dropping `PackageCache`'s closest-package memo, which also cuts the resolver's retained heap by ~37% (#1945, #1946, #1948 by @robhogan)
 - **[Performance]**: ~33% faster non-Watchman file system crawl on startup (#1677 by @kitten)
 - **[Deprecated]**: `server.enhanceMiddleware` logs a deprecation warning when set to anything other than its default. Use `server.unstable_middleware` or `server.unstable_priorityMiddleware` (#2031 by @vzaidman)
 - **[Deprecated]**: `runServer`'s `unstable_extraMiddleware` option. Use `unstable_priorityMiddleware`, which runs the same middleware in the same place (#2031 by @vzaidman)
 - **[Deprecated]**: String values of `transformer.enableBabelRuntime` (use `true`) (#1957 by @robhogan)
 - **[Types]**: Add TypeScript definitions for `metro-runtime` modules, and generate (rather than hand-maintain) types for `metro-file-map` workers (#1996 by @robhogan)

> NOTE: Experimental features are not covered by semver and can change at any time.

 - **[Experimental]**: Add `server.unstable_middleware` and `server.unstable_priorityMiddleware` config options, and `runServer` options of the same names, to add middleware after and before Metro's own. `mergeConfig` combines them from both configs: a later config's `unstable_middleware` runs last and its `unstable_priorityMiddleware` runs first (#2031 by @vzaidman)
 - **[Experimental]**: Add `server.unstable_onServerCreated` config option and `runServer` option of the same name, called with Metro's server instance before the HTTP server listens (#2031 by @vzaidman)
 - **[Experimental]**: Fix mismatched asset paths in (release) builds under `unstable_serverRoot`, make them always relative to `projectRoot` (#1917 by @robhogan)

 **Full Changelog**: v0.87.1...v0.87.2
```
robhogan added a commit that referenced this pull request Oct 23, 2026
… build

#2007 revisits an added file the graph already holds by copying it into the modified set, leaving it in the added set too. If that build fails, both sets are restored, and a deletion of the file then cancels out against the addition, leaving it modified and not deleted. Every later build traverses the missing file and fails with "Failed to get the SHA-1", until it's recreated.

This moves the file from added to modified instead.

Changelog: Internal

Test plan:
New unit test, which fails without this change.
robhogan added a commit that referenced this pull request Oct 23, 2026
… build

Since #2007, a re-added file the graph already holds stays in the added set as well as modified. After a failed build, deleting it cancels the addition and leaves it modified:

```
foo deleted and re-added during build N  -> build N+1 revisits foo, fails
foo deleted                              -> every build: "Failed to get the SHA-1 for: foo"
```

This moves it from added to modified instead.

Changelog: Internal

Test plan:
- New unit test, failing without this change.
robhogan added a commit that referenced this pull request Oct 26, 2026
… build (#2098)

Since #2007, a re-added file the graph already holds stays in the added set as well as modified. After a failed build, deleting it cancels the addition and leaves it modified:

```
foo deleted and re-added during build N  -> build N+1 revisits foo, fails
foo deleted                              -> every build: "Failed to get the SHA-1 for: foo"
```

This moves it from added to modified instead.

Changelog: Internal

Test plan:
- New unit test, failing without this change.
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. 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.

2 participants