-
Couldn't load subscription status.
- Fork 84
Description
New in [email protected]: when using the Chrome debugger, the app bundle is now run inside a web worker: facebook/react-native#1632, facebook/react-native@8db35d4
This means that an app bundle built with webpack's hot module replacement enabled will raise errors such as #99, and hot module replacement will fail.
I'm able to get HMR working on the rn-0.12-hmr branch by doing the following:
-
Use webpack-dev-middleware + webpack-hot-middleware instead of webpack/hot/only-dev-server + webpack-dev-server/client:
webpack-dev-server depends on
window.postMessageto broadcast "webpackHotUpdate" events to any loaded scripts (usually just'webpack/hot/dev-server'or'webpack/hot/only-dev-server'), which does not work in the context of a web worker since web workers have a differentpostMessageAPI. webpack-hot-middleware is an alternative which combines the functionality of bothwebpack/hot/only-dev-serverandwebpack-dev-server/client. -
Patch webpack so it uses
importScriptsinside a web worker instead of the default behaviour of appending a<script>with the new hot-reloaded module: elliottsj/webpack@743a00a.Known issue: this inexplicable error is thrown every time a module is hot reloaded:
Edit: turns out this was caused by addingwebpack.HotModuleReplacementPlugin()to the config twice instead of once (-‸ლ)
Not sure why this happens; the original error message & stack gets lost somewhere.
Try out rn-0.12-hmr/Examples/BabelES6 for a working example.
My patch to webpack seems quite hacky; I think the proper solution is to make something like 'WebWorkerMainTemplate.runtime.js', but I don't know enough about webpack internals to know what to do here.
Does anyone have any ideas on the proper way to do HMR from inside the web worker? cc @gaearon @sokra