Skip to content

Commit

Permalink
Fix HMR when adding/renaming assets
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rafeca authored and facebook-github-bot committed Aug 24, 2017
1 parent b6e0f4a commit 79fdb91
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions local-cli/server/util/attachHMRServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
return;
}

const deps = await packagerServer.getShallowDependencies({
dev: true,
minify: false,
Expand Down Expand Up @@ -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
Expand All @@ -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 => {
Expand Down

0 comments on commit 79fdb91

Please sign in to comment.