Break infinite loop when trying to hot patch circular dependencies

Reviewed By: BYK

Differential Revision: D6853993

fbshipit-source-id: 9e42d207738102e019fccea517411fccd0fb6b1b
This commit is contained in:
Rafael Oleza 2018-02-05 21:38:51 -08:00 committed by Facebook Github Bot
parent e329f00dc9
commit e162ea7698
1 changed files with 19 additions and 2 deletions

View File

@ -47,6 +47,7 @@ type ModuleDefinition = {|
verboseName?: string, verboseName?: string,
|}; |};
type ModuleMap = {[key: ModuleID]: ModuleDefinition, __proto__: null}; type ModuleMap = {[key: ModuleID]: ModuleDefinition, __proto__: null};
type PatchedModules = {[ModuleID]: boolean};
type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports; type RequireFn = (id: ModuleID | VerboseModuleNameForDev) => Exports;
type VerboseModuleNameForDev = string; type VerboseModuleNameForDev = string;
@ -271,7 +272,11 @@ if (__DEV__) {
return hot; return hot;
}; };
const acceptAll = function(dependentModules, inverseDependencies) { const acceptAll = function(
dependentModules,
inverseDependencies,
patchedModules,
) {
if (!dependentModules || dependentModules.length === 0) { if (!dependentModules || dependentModules.length === 0) {
return true; return true;
} }
@ -283,6 +288,7 @@ if (__DEV__) {
/*factory*/ undefined, /*factory*/ undefined,
/*dependencyMap*/ undefined, /*dependencyMap*/ undefined,
inverseDependencies, inverseDependencies,
patchedModules,
), ),
); );
@ -304,7 +310,14 @@ if (__DEV__) {
factory?: FactoryFn, factory?: FactoryFn,
dependencyMap?: DependencyMap, dependencyMap?: DependencyMap,
inverseDependencies: {[key: ModuleID]: Array<ModuleID>}, inverseDependencies: {[key: ModuleID]: Array<ModuleID>},
patchedModules: PatchedModules = {},
) { ) {
if (id in patchedModules) {
// Do not patch the same module more that once during an update.
return true;
}
patchedModules[id] = true;
const mod = modules[id]; const mod = modules[id];
if (!mod && factory) { if (!mod && factory) {
@ -342,7 +355,11 @@ if (__DEV__) {
} }
// accept parent modules recursively up until all siblings are accepted // accept parent modules recursively up until all siblings are accepted
return acceptAll(inverseDependencies[id], inverseDependencies); return acceptAll(
inverseDependencies[id],
inverseDependencies,
patchedModules,
);
} }
}; };