Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): fix hot-reloading for hooks (patch hmr) #13713

Merged
merged 7 commits into from
May 17, 2019

Conversation

wardpeet
Copy link
Contributor

Should fix hot-reloading issues for new react features (hooks) and also fix the issue with You must provide the URL of lib/mappings.wasm. A few packages use isomorphic-fetch which polyfills global.fetch.

The source-map package doesn't deal with pollyfilled versions so it will go for the web version instead of trying to load wasm with nodejs. (https://github.com/mozilla/source-map/blob/0.7.3/lib/read-wasm.js#L1). It's fixed in 0.8.0-beta but it hasn't been released for a while so for now I manually monkey patch the hmr package.

// error:

error UNHANDLED REJECTION

  Error: You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
  
  - read-wasm.js:8 readWasm
    [www]/[react-hot-loader]/[source-map]/lib/read-wasm.js:8:13
  
  - wasm.js:25 wasm
    [www]/[react-hot-loader]/[source-map]/lib/wasm.js:25:16
  
  - source-map-consumer.js:264 BasicSourceMapConsumer.then.that
    [www]/[react-hot-loader]/[source-map]/lib/source-map-consumer.js:264:14

You can test this PR on gatsby-www or create a new starter and include isomorphic-fetch inside gatsby-config.js

References:
#13610 (comment)
#13641

@wardpeet wardpeet changed the title Fix/hmr issue fix(gatsby): fix hot-reloading for hooks (patch hmr) Apr 29, 2019
@wardpeet
Copy link
Contributor Author

I'll also create a PR on react-hot-reloader, might not get accepted but than we can remove our monkey patch in a next version of gatsby.

@mbifulco
Copy link
Contributor

mbifulco commented May 7, 2019

Hey @wardpeet - I'd love to test this on a project that's giving me trouble. How can I reference your PR in package.json to pull in this specific version of gatsby?

@wardpeet
Copy link
Contributor Author

it's not that easy, you'll need to follow https://www.gatsbyjs.org/blog/2018-04-11-trying-out-gatsby-at-work-and-co/#branching-off which might give you insights on how to.

@@ -1,3 +1,8 @@
// isomorphic-fetch sets global.fetch which seems to conflicts with source-map@<0.8.0 where it does a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂

Copy link
Contributor

@sidharthachatterjee sidharthachatterjee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you as always @wardpeet 🥇

@sidharthachatterjee sidharthachatterjee merged commit 117fbb4 into gatsbyjs:master May 17, 2019
@sidharthachatterjee
Copy link
Contributor

Published in gatsby@2.5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants