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

add react-refresh hot reloading #5246

Merged
merged 1 commit into from
Jun 1, 2020

Conversation

glekner
Copy link
Contributor

@glekner glekner commented Apr 30, 2020

This adds the react-refresh webpack plugin, which makes hot component reloading really work.
My webpack PR from 8 months ago enabled an auto reload, with hot reload we won't even need to reload.
This is very beneficial for us because of websockets, they remain in tact so we don't have to wait for a cluster far away, therefore we can develop and debug a LOT faster.

This won't work for all file changes, and once they don't - a full reload is triggered ( just like the current behaviour)
files that won't hot reload:

  1. components/selectors/constants that are exported like this export * from
  2. combining a component and render logic in the same file (just like our very own app.jsx)

@spadgett @alecmerdler thoughts?

@glekner glekner changed the title Experimental - add react-refresh hot reloading add react-refresh hot reloading Apr 30, 2020
@spadgett
Copy link
Member

/cc @christianvogt @vojtechszocs

@christianvogt
Copy link
Contributor

Sounds like a win to me.
I miss the days of working on projects with hot reloading that doesn't refresh the page.

@@ -162,6 +167,7 @@
"@types/react-transition-group": "2.x",
"@types/react-virtualized": "9.x",
"@types/webpack": "4.x",
"babel-loader": "^8.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

We need Babel now on top of TypeScript?

Comment on lines 73 to 78
{
loader: 'babel-loader',
options: {
plugins: [isDevelopment && 'react-refresh/babel'],
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

babel-loader should only be added if isDevelopment === true

@christianvogt
Copy link
Contributor

Are there any performance changes with using babel now in dev startup and recompiling?

@glekner
Copy link
Contributor Author

glekner commented May 3, 2020

@christianvogt @alecmerdler
fixed suggestions.
We do need babel now with this plugin but it doesn't hurt performance at all.
Compile and recompile time is the same for me.
from @pmmmwh plugin:

If you are using TypeScript (instead of Babel) as a transpiler, you will still need to use babel-loader to process your source code.

Without PR changes:
Screen Shot 2020-05-03 at 11 19 46

With PR changes:
Screen Shot 2020-05-03 at 11 24 32

@glekner
Copy link
Contributor Author

glekner commented May 11, 2020

  • updated packages

@spadgett
Copy link
Member

@glekner Thanks for the PR. I'm on board.

You have a Webpack error, though.

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration.module.rules[1].use should be one of these:
   non-empty string | function | object { ident?, loader?, options?, query? } | function | [non-empty string | function | object { ident?, loader?, options?, query? }]
   -> Modifiers applied to the module when rule is matched
   Details:
    * configuration.module.rules[1].use[2] should be a string.
    * configuration.module.rules[1].use[2] should be an instance of function
    * configuration.module.rules[1].use[2] should be an object.
    * configuration.module.rules[1].use[2] should be one of these:
      non-empty string | function | object { ident?, loader?, options?, query? }
    * configuration.module.rules[1].use[2] should be one of these:
      non-empty string | function | object { ident?, loader?, options?, query? }
      -> An use item
 - configuration.plugins[7] should be one of these:
   object { apply, … } | function
   -> Plugin of type object or instanceof Function
   Details:
    * configuration.plugins[7] should be an object.
      -> Plugin instance
    * configuration.plugins[7] should be an instance of function
      -> Function acting as plugin
error Command failed with exit code 1.

@glekner
Copy link
Contributor Author

glekner commented May 11, 2020

/retest

@glekner
Copy link
Contributor Author

glekner commented May 11, 2020

@spadgett this is weird, my env works well.
can you try

  1. removing node modules and reinstalling
  2. installing webpack-dev-server globally
    and try again?

@openshift-ci-robot openshift-ci-robot added component/core Related to console core functionality component/dev-console Related to dev-console component/knative Related to knative-plugin component/kubevirt Related to kubevirt-plugin component/olm Related to OLM labels May 11, 2020
@spadgett
Copy link
Member

@glekner The error is not in my environment. It's in CI (which uses a fresh workspace).

Did you try ./build-frontend.sh as opposed to yarn run dev?

@@ -68,6 +70,12 @@ const config: Configuration = {
workers: require('os').cpus().length - 1,
},
},
isDevelopment && {
Copy link
Member

Choose a reason for hiding this comment

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

This looks like the cause of the error. Won't this add false to the array when not in development mode?

@glekner glekner force-pushed the react-refresh-lite branch 4 times, most recently from 8dde73a to e694fc3 Compare May 13, 2020 10:23
@glekner
Copy link
Contributor Author

glekner commented May 13, 2020

@spadgett

  • Added filter(Boolean) to rules, plugins arrays to fix production build

@glekner
Copy link
Contributor Author

glekner commented May 17, 2020

@spadgett removed .filter(Boolean)

Also created #5467
As a first step towards 100% hot module replacement.

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 20, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label May 25, 2020
@glekner
Copy link
Contributor Author

glekner commented May 25, 2020

@spadgett upgraded plugin version

Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 26, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: glekner, spadgett

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 0b55e38 into openshift:master Jun 1, 2020
@spadgett spadgett added this to the v4.6 milestone Jun 1, 2020
@spadgett spadgett added the kind/dependency-change Categorizes issue or PR as related to changing dependencies label Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/dev-console Related to dev-console component/knative Related to knative-plugin component/kubevirt Related to kubevirt-plugin component/olm Related to OLM kind/dependency-change Categorizes issue or PR as related to changing dependencies lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants