next.js
dc9ba02f - Turbopack: Setup HMR for client-only changes in App dir (#55464)

Commit
3 years ago
Turbopack: Setup HMR for client-only changes in App dir (#55464) ### What? This sets up the Turbopack HMR client to listen for client-only changes in App Pages. In the [initial PR](https://github.com/vercel/next.js/pull/54772), I incorrectly assumed that client-only changes would trigger a page refresh, so we didn't need an actual HMR client listening for changes. But, that's wrong, and it was a bug in our change event listeners that caused the refresh (we detected a change from a sourcemap that was reemitted and considered part of the RSC server bundle). ### Why? HMR makes development tolerable. ### How? We initialize the Turbopack HMR client and have it send and receive messages from `HotReloader`'s web socket. If a client change is detected, Turbopack's HMR runtime will reevaluate the module and update the page accordingly. ### TODO: There's a bug in our Turbopack "compile time" evaluation. We should be able to detect that the client bundle is compiled by Turbopack via the `process.turbopack` and `process.env.TURBOPACK` values (they're compiled to truthy expressions by Turbopack). But for some reason, neither is working! This means that we're including the turbopack HMR client in the wepback bundle, and doing some function calls (that will never actually do anything). While not ideal, it's so negligible that it shouldn't block merging this. Closes WEB-1588
Author
Parents
Loading