question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support Fast Refresh

See original GitHub issue

Describe the feature

We’ve landed Fast Refresh on React Native master. You can try it if you build all Metro packages from master and replace them in node_modules of RNTester.

Motivation

It would be nice if Haul could replace react-hot-loader or other techniques with Fast Refresh because:

  • Fast Refresh doesn’t create semantic differences in behavior (so it’s safe to always leave on, unlike solutions based on react-hot-loader and similar tools)
  • Fast Refresh fully supports function components and Hooks, including cases where you add or remove Hooks
  • Fast Refresh gracefully recovers from errors

It likely also fixes hot reloading problems with navigation libraries because it’s fully integrated with React. (Although I don’t have a test case to verify that.)

It would also unify the behavior with mainline React Native.

But How?

I’d be happy to chat with someone to give an overview of how the new system works. For a 100% match in behavior we might need some new hooks from webpack, but you should be able to get reasonably close today too.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:27
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
thymikeecommented, Jun 29, 2019

We develop the next version of haul on next branch and disabled hot loader because it was just too hacky. We’re happy to give Fast Refresh a try. Cc @zamotany who’s developing Haul at the moment

1reaction
zamotanycommented, May 26, 2020

To anyone interested in the issue.

There’s a common misconception that just because something is built for Webpack, it will work out of the box for React Native with Haul. 90% of the time it doesn’t. Anything that’s. being built for Webpack targets web and uses browser API.

From the investigation done some time ago here are the takeaways what would have to be done in order to support React Refresh in Haul. The fast refresh is terribly complex issue and it would require major changes and additions to support. As a base for investigation I did some time ago, I used https://github.com/pmmmwh/react-refresh-webpack-plugin:

  1. New React Refresh plugin should be created for Haul with React Native specifics in mind. It would require a lot of resources to port/workaround pmmmwh/react-refresh-webpack-plugin usage of browser specific APIs, because in Haul to support RN platform there’a a lot of tweaking and additional code that has to run in specific order. With the way pmmmwh/react-refresh-webpack-plugin is built, this order is not kept which results in crashes.

  2. Some tweaking in Webpack config will be necessary. For sure adding a HotModuleReplacementPlugin. Given my experience with working with this plugin, it also assumes that the browser APIs will be present, which means we would need to workaround or hack this usage somehow.

  3. To support HotModuleReplacementPlugin (which is needed to support React Refresh plugin) there’s a need for major refactor for the server/compiler architecture that Haul is currently using. For each platform it would need a separate Webpack Hot Middleware so essentially we would need for each platform:

    • A platform-specific Webpack compiler (eg. Webpack compiler for iOS)
    • A platform-specific packager server (eg. packager server for iOS)
    • A platform-specific Webpack hot middleware injected into the platform-specific packager server
  4. And then a single proxy packager server that would proxy requests for specific platform to each platform-specific packager server. The platform-specific Webpack compiler, platform-specific server and platform-specific hot middleware together will have to be spawned in a separate process/thread.

To summarise: there are a lot of moving parts to get this working and it requires extensive/deep knowledge about how Webpack works - more specifically what parts are put into the final bundle, how the module system and Webpack logic working in the bundle and how HotModuleReplacementPlugin itself works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Features: Fast Refresh - Next.js
Next.js' Fast Refresh is a new hot reloading experience that gives you instantaneous feedback on edits made to your React components.
Read more >
Welcome to craco-fast-refresh - GitHub
A Craco plugin to enable "Fast Refresh" (also previously known as Hot Reloading) for React components. What is Fast Refresh. React Fast Refresh...
Read more >
React Fast Refresh — The New React Hot Reloader
A Comprehensive Guide to Using React Fast Refresh. ... contains the basic tooling needed support React Fast Refresh's hot reloading ...
Read more >
Fast Refresh | Gatsby
Fast Refresh is an implementation of Hot Reloading with full support from React. It replaces unofficial solutions like react-hot-loader . With Fast Refresh...
Read more >
What the heck is React Fast Refresh | Marios Fakiolas
React Fast Refresh is the successor of React Hot Loader . It is fully supported by the React team and was initially shipped...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found