-
Notifications
You must be signed in to change notification settings - Fork 143
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
Client-side hot reloading / HMR #630
Conversation
This would fix the CI tests too.
* add /__mrt/hmr and remove publicPath * update loadable extractor * remove debuggers * remove getPublicPath * fix src path * update /__mrt/hmr endpoint * use 501 for disabled endpoint
|
||
const rules = [ | ||
ruleForBabelLoader([require.resolve('react-refresh/babel')]), | ||
...config.module.rules.slice(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems fragile... can we give the loader rules an id
and replace by id
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevinxh I've tried adding an id and it failed because not matching the expected config schema. That's why I end up with this instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like the Builder
class lacks some basic functionalities. We need to be able to manipulate the config in a safer manner. Imagine we have many extend
function calls and each of them adds/removes different rules, it's gonna be hard to maintain the webpack config.
@@ -71,6 +71,7 @@ | |||
"save-credentials": "pwa-kit-dev save-credentials", | |||
"start": "cross-env NODE_ICU_DATA=node_modules/full-icu pwa-kit-dev start", | |||
"start:inspect": "npm run start -- --inspect", | |||
"start:no-hmr": "npm run start -- --noHMR", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we want to have this as an project OOTB npm script. because if this feature works well, i'd imagine developers should never turn if off, or on a very very very rare case.
Disabling-hmr is still available in the CLI.
@@ -206,6 +209,7 @@ const withChunking = (config) => { | |||
|
|||
const ruleForBabelLoader = (babelPlugins) => { | |||
return { | |||
id: 'javascript', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javascript
is the target language for this rule but I feel more natural to call this the babel-loader
, I feel like babel-loader
kinda implies it is js/ts and it is also a little bit more descriptive?
...config.module.rules.slice(1) | ||
] | ||
const newRule = ruleForBabelLoader([require.resolve('react-refresh/babel')]) | ||
const rules = findAndReplace(config.module.rules, (rule) => rule.id === 'javascript', newRule) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed that in the future, we might expose functionality for end users to customize specific rules. Maybe via the Builder
class. However, that's out side of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very excited to ship this feature!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't forget to update changelog :)
Description
This PR adds a new feature to the runtime SDK, the one that all front-end developers love and are used to using it for granted nowadays, which is CLIENT SIDE HOT RELOADING!
With client side hot reloading, developers can save their changes in code editor and see the changes reflected on the browser immediately, without refreshing the web page.
See it in action:
Screen.Recording.2022-05-25.at.5.00.33.PM.mov
Related PR #379
TODO:
Types of Changes
Changes
@pmmmwh/react-refresh-webpack-plugin
andreact-refresh
How to Test-Drive This PR
npm start
in typescript template or retail react appChecklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization