From 15054ade7deac35755fd1ba0fcc3212ca5b2dfde Mon Sep 17 00:00:00 2001 From: Bhuwan Khattar Date: Thu, 15 Oct 2015 18:27:53 -0700 Subject: [PATCH] Support cyclic dependencies in require polyfill Reviewed By: @martinbigio Differential Revision: D2548506 fb-gh-sync-id: fca534179a5f8fcf407917137cdd71d964f145e5 --- .../src/DependencyResolver/polyfills/require.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packager/react-packager/src/DependencyResolver/polyfills/require.js b/packager/react-packager/src/DependencyResolver/polyfills/require.js index 2f9015f61..b674ba4ec 100644 --- a/packager/react-packager/src/DependencyResolver/polyfills/require.js +++ b/packager/react-packager/src/DependencyResolver/polyfills/require.js @@ -50,12 +50,16 @@ } try { + // We must optimistically mark mod as initialized before running the factory to keep any + // require cycles inside the factory from causing an infinite require loop. + mod.isInitialized = true; + // keep args in sync with with defineModuleCode in // packager/react-packager/src/DependencyResolver/index.js mod.factory.call(global, global, require, mod.module, mod.module.exports); - mod.isInitialized = true; } catch (e) { mod.hasError = true; + mod.isInitialized = false; throw e; }