Browse files

Fix HMR when adding/renaming assets

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
  • Loading branch information...
rafeca authored and facebook-github-bot committed Aug 24, 2017
1 parent b6e0f4a commit 79fdb91bb777c6c09296222b5f0615c36e31bf8e
Showing with 9 additions and 5 deletions.
  1. +9 −5 local-cli/server/util/attachHMRServer.js
@@ -239,6 +239,12 @@ function attachHMRServer<TModule: Moduleish>(
client: Client,
filename: string,
): Promise<?HMRBundle> {
// If the main file is an asset, do not generate a bundle.
const moduleToUpdate = await packagerServer.getModuleForPath(filename);
if (moduleToUpdate.isAsset()) {
const deps = await packagerServer.getShallowDependencies({
dev: true,
minify: false,
@@ -269,9 +275,9 @@ function attachHMRServer<TModule: Moduleish>(
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<TModule: Moduleish>(
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 => {

0 comments on commit 79fdb91

Please sign in to comment.