From 56c3a581b04a8e279d2a66cd8d814aff72e1b061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Bigio?= Date: Mon, 16 May 2016 10:28:37 -0700 Subject: [PATCH] Avoid clearing out factory on DEV mode Summary: grabbou pointed out this issue. We recently started cleaning out the factory function after module are required to save some memory. This broke HMR on some edge cases because sometimes the factory function may need to be re-executed. This PR just wraps the optimization into `__DEV__` to make sure we don't use it while developing. Closes https://github.com/facebook/react-native/pull/7568 Differential Revision: D3305120 Pulled By: martinbigio fbshipit-source-id: 741cffbb327d118f0bd0ec34dc1af53d4f94880e --- react-packager/src/Resolver/polyfills/require.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/react-packager/src/Resolver/polyfills/require.js b/react-packager/src/Resolver/polyfills/require.js index c31ba095..219a4bad 100644 --- a/react-packager/src/Resolver/polyfills/require.js +++ b/react-packager/src/Resolver/polyfills/require.js @@ -120,7 +120,11 @@ function loadModuleImplementation(moduleId, module) { // keep args in sync with with defineModuleCode in // packager/react-packager/src/Resolver/index.js factory(global, require, moduleObject, exports); - module.factory = undefined; + + // avoid removing factory in DEV mode as it breaks HMR + if (!__DEV__) { + module.factory = undefined; + } if (__DEV__) { Systrace.endEvent();