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

Fast refresh si loaded twice #193

Closed
4 tasks done
Relaxe111 opened this issue Jul 6, 2023 · 4 comments · Fixed by #194
Closed
4 tasks done

Fast refresh si loaded twice #193

Relaxe111 opened this issue Jul 6, 2023 · 4 comments · Fixed by #194

Comments

@Relaxe111
Copy link

Description

As a developer using vite in an micro front end environment we do need to have multiple loads of the @react-refresh when we are in dev mode with multiple micro apps.
In version 4 was added a throw error when one has multiple loads of the react-refresh which we do, because they are located on different urls, while window object is shared with all micro-apps.
And window.vite_plugin_react_runtime_loaded is shared as well which will cause a throw, and any micro app after first loaded micro app will die.

CleanShot 2023-07-06 at 11 26 10@2x

Suggested solution

Could we add an option which can disable react-refresh throw React refresh runtime was loaded twice...?

/* eslint-disable no-undef */
if (typeof window !== 'undefined') {
    **if(!disableThrowMultiLoading){**
      if (window.__vite_plugin_react_runtime_loaded__) {
        throw new Error(
          'React refresh runtime was loaded twice. Maybe you forgot the base path?',
        )
      }
    **}**
  window.__vite_plugin_react_runtime_loaded__ = true
}

Alternative

Alternative can be not to throw but to console.warn this.

/* eslint-disable no-undef */
if (typeof window !== 'undefined') {
 
      if (window.__vite_plugin_react_runtime_loaded__) {
       --// throw new Error(
       ++ console.warn(
          'React refresh runtime was loaded twice. Maybe you forgot the base path?',
        )
      }

  window.__vite_plugin_react_runtime_loaded__ = true
}

Additional context

No response

Validations

@ArnaudBarre
Copy link
Member

See discussion here #185

How do you manage to load React only one time currently?

@Relaxe111
Copy link
Author

Relaxe111 commented Jul 6, 2023

If I understand correctly you're question, I do load for each project individual React version, with their own /react-refresh. I am using qiankun(single-spa) setup for that, which does runtime assembly of the apps. All micro apps having its owns dev servers, setups, and have its own repos, builds etc.
Our current workflow is: I am going to a dev url ex: https://dev.advoca.no. and on right down side i have a button, where I can override micro-apps urls with local instances of micro apps running locally, each local micro app in dev mode loads its own React version and /react-refresh, they run independently and can have different versions.

Prior v 4 I can override as much micro-apps as i need, with no problem.

@ArnaudBarre
Copy link
Member

I released 4.0.3 without this check!

@Relaxe111
Copy link
Author

thanks a lot!!!

@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants