Skip to content

Fast refresh si loaded twice #193

Closed
@Relaxe111

Description

@Relaxe111

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions