Skip to content

Commit

Permalink
Force reload at split points when Metro restarts
Browse files Browse the repository at this point in the history
Summary:
In https://fb.workplace.com/groups/rn.support/permalink/3132785890103338/?comment_id=3132873900094537 we identified that when Metro restarts but the app keeps the main bundle alive, the next request for a split bundle will always produce an invalid bundle. This is because we rely on module ids being stable while Metro is running and when Metro is restarted, those module ids will likely be assigned to different modules.

The fix applied here simply forces a full reload when downloading (registering) a new split bundle if the connection to Metro disappeared.

Another way to mitigate this is to use stable module ids. That's a more involved change in Metro that I'm not planning on making right now.

Changelog: [Internal]

Reviewed By: rickhanlonii

Differential Revision: D19235555

fbshipit-source-id: b8ff10590655952a2af1379bbf4e930f9eb95c1b
  • Loading branch information
cpojer authored and facebook-github-bot committed Dec 27, 2019
1 parent fa8b4f5 commit 022f9cc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Libraries/Utilities/HMRClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

'use strict';

const DevSettings = require('./DevSettings');
const Platform = require('./Platform');
const invariant = require('invariant');

Expand Down Expand Up @@ -274,6 +275,11 @@ function setHMRUnavailableReason(reason) {
}

function registerBundleEntryPoints(client) {
if (hmrUnavailableReason) {
DevSettings.reload('Bundle Splitting – Metro disconnected');
return;
}

if (pendingEntryPoints.length > 0) {
client.send(
JSON.stringify({
Expand Down

0 comments on commit 022f9cc

Please sign in to comment.