From 46b02dc021d257490ba25d6e102326f451e714b8 Mon Sep 17 00:00:00 2001 From: Rob Hogan Date: Fri, 22 Dec 2023 08:01:37 -0800 Subject: [PATCH] Remove Fast Refresh bail-out in DeltaCalculator on certain errors Summary: Since D51665495, a transform or resolution error encountered while processing modified files will throw *before any change is committed to `Graph`'s state*, so if `DeltaCalculator` catches an error we can be confident `Graph` is still in a good state. Previously this might've left a modification partially applied to the graph (I assume that's what's meant by "weird state" in the comment here), so `DeltaCalculator` would attempt to detect that and force a reset update. That creates extra work both for Metro (especially as the next modification might not fix the error, we would re-traverse the whole graph on any change perhaps multiple times), and the client, having a full reset to process. It's no longer necessary. (Note that in any case this safety net had gaps - it was always possible for a bad update to both add and remove modules such that the overall size didn't change.) Changelog: ``` **[Fix]:** Don't unnecessarily reset Fast Refresh after recovering from certain transform or resolution errors. ``` Reviewed By: GijsWeterings Differential Revision: D52193122 fbshipit-source-id: 65516257edb0a2cad79c3346f946ab960b7dfc70 --- packages/metro/src/DeltaBundler/DeltaCalculator.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/packages/metro/src/DeltaBundler/DeltaCalculator.js b/packages/metro/src/DeltaBundler/DeltaCalculator.js index 61cfb48d3c..402bdc6a5a 100644 --- a/packages/metro/src/DeltaBundler/DeltaCalculator.js +++ b/packages/metro/src/DeltaBundler/DeltaCalculator.js @@ -133,8 +133,6 @@ class DeltaCalculator extends EventEmitter { let result; - const numDependencies = this._graph.dependencies.size; - try { result = await this._currentBuildPromise; } catch (error) { @@ -146,13 +144,6 @@ class DeltaCalculator extends EventEmitter { deletedFiles.forEach((file: string) => this._deletedFiles.add(file)); addedFiles.forEach((file: string) => this._addedFiles.add(file)); - // If after an error the number of modules has changed, we could be in - // a weird state. As a safe net we clean the dependency modules to force - // a clean traversal of the graph next time. - if (this._graph.dependencies.size !== numDependencies) { - this._graph.dependencies.clear(); - } - throw error; } finally { this._currentBuildPromise = null;