Skip to content

Commit

Permalink
Add deleted modules to HMR update
Browse files Browse the repository at this point in the history
Reviewed By: mjesun

Differential Revision: D10489002

fbshipit-source-id: a7df2a65b4be2b2f7442e57cca1f58446c78c81c
  • Loading branch information
Alexandre Kirszenberg authored and facebook-github-bot committed Oct 29, 2018
1 parent b73212a commit 95441e8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/metro/src/DeltaBundler/Serializers/hmrJSBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function hmrJSBundle(
options: Options,
): {|
+modules: ModuleMap,
+deleted: $ReadOnlyArray<number>,
+sourceMappingURLs: $ReadOnlyArray<string>,
+sourceURLs: $ReadOnlyArray<string>,
|} {
Expand Down Expand Up @@ -59,7 +60,12 @@ function hmrJSBundle(
}
}

return {modules, sourceMappingURLs, sourceURLs};
return {
modules,
deleted: [...delta.deleted].map(path => options.createModuleId(path)),
sourceMappingURLs,
sourceURLs,
};
}

function _prepareModule(
Expand Down
3 changes: 2 additions & 1 deletion packages/metro/src/HmrServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class HmrServer<TClient: Client> {

client.revisionId = revision.id;

const {modules, sourceMappingURLs, sourceURLs} = hmrJSBundle(
const {modules, deleted, sourceMappingURLs, sourceURLs} = hmrJSBundle(
delta,
revision.graph,
{
Expand All @@ -197,6 +197,7 @@ class HmrServer<TClient: Client> {
body: {
revisionId: revision.id,
modules,
deleted,
sourceMappingURLs,
sourceURLs,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/metro/src/HmrServer/__tests__/HmrServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ describe('HmrServer', () => {
},
delta: {
modified: new Map([['/root/hi', hiModule]]),
deleted: new Set(['/root/bye']),
},
}),
);
Expand All @@ -196,6 +197,7 @@ describe('HmrServer', () => {
'__d(function() { alert("hi"); },"/root/hi-id",[],"hi",{});',
],
],
deleted: ['/root/bye-id'],
sourceURLs: ['/root/hi'],
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/metro/src/lib/bundle-modules/types.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type FormattedError = {|
export type HmrUpdate = {|
+revisionId: string,
+modules: ModuleMap,
+deleted: $ReadOnlyArray<number>,
+sourceMappingURLs: $ReadOnlyArray<string>,
+sourceURLs: $ReadOnlyArray<string>,
|};
Expand Down

0 comments on commit 95441e8

Please sign in to comment.