From 79fdb91bb777c6c09296222b5f0615c36e31bf8e Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Thu, 24 Aug 2017 07:26:48 -0700 Subject: [PATCH] Fix HMR when adding/renaming assets Summary: The HMR logic used to try to calculate the dependencies of every new added (or modified) file, including assets. This resulted in a TransformError. This commit adds a check that stops the HMR bundling once it finds out that the updated file is an asset Reviewed By: cpojer Differential Revision: D5697391 fbshipit-source-id: faf7ccad76ac4922b70ed1c7ce8ce32b03c4e8ee --- local-cli/server/util/attachHMRServer.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/local-cli/server/util/attachHMRServer.js b/local-cli/server/util/attachHMRServer.js index 49e85e766..4632ddc59 100644 --- a/local-cli/server/util/attachHMRServer.js +++ b/local-cli/server/util/attachHMRServer.js @@ -239,6 +239,12 @@ function attachHMRServer( client: Client, filename: string, ): Promise { + // If the main file is an asset, do not generate a bundle. + const moduleToUpdate = await packagerServer.getModuleForPath(filename); + if (moduleToUpdate.isAsset()) { + return; + } + const deps = await packagerServer.getShallowDependencies({ dev: true, minify: false, @@ -269,9 +275,9 @@ function attachHMRServer( recursive: true, }); - const module = await packagerServer.getModuleForPath(filename); - - resolutionResponse = await response.copy({dependencies: [module]}); + resolutionResponse = await response.copy({ + dependencies: [moduleToUpdate]}, + ); } else { // if there're new dependencies compare the full list of // dependencies we used to have with the one we now have @@ -283,8 +289,6 @@ function attachHMRServer( resolutionResponse: myResolutionReponse, } = await getDependencies(client.platform, client.bundleEntry); - const moduleToUpdate = await packagerServer.getModuleForPath(filename); - // build list of modules for which we'll send HMR updates const modulesToUpdate = [moduleToUpdate]; Object.keys(depsModulesCache).forEach(module => {