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

Vite: replace <LiveReload/> with <DevScripts/> #8609

Closed
wants to merge 5 commits into from
Closed

Conversation

pcattori
Copy link
Contributor

@pcattori pcattori commented Jan 26, 2024

This is a breaking change for projects using the unstable Vite plugin.

The <LiveReload/> component has a confusing name as it now also supports HMR and HDR.
Additionally, it provides an bespoke client-side runtime that is obsoleted by Vite.
To get our Vite plugin working, we were doing some compiler magic to swap out the
implementation of <LiveReload/>.
This was always meant as a temporary measure.

Now we have a better solution in the form of a new <DevScripts/> component specifically
designed with Vite's HMR capabilities in mind.

The <LiveReload /> component will cease to provide HMR and HDR capabilities in Vite,
so you'll need to replace <LiveReload/> with <DevScripts/> in your app.

The <DevScripts/> component should be placed in the <head/> of your app so that it
can be loaded before any other scripts as required by React Fast Refresh.

  import {
-   LiveReload,
+   DevScripts,
    Outlet,
  }

  export default function App() {
    return (
      <html>
        <head>
+         <DevScripts />
        </head>
        <body>
-         <LiveReload />
          <Outlet />
        </body>
      </html>
    )
  }

Tried to directly inject the HMR runtime into the <head/> instead (#8604) but that still had issues with race conditions.

Copy link

changeset-bot bot commented Jan 26, 2024

🦋 Changeset detected

Latest commit: d0d8428

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@remix-run/dev Patch
@remix-run/react Patch
@remix-run/testing Patch
create-remix Patch
remix Patch
@remix-run/architect Patch
@remix-run/cloudflare Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/css-bundle Patch
@remix-run/deno Patch
@remix-run/eslint-config Patch
@remix-run/express Patch
@remix-run/node Patch
@remix-run/serve Patch
@remix-run/server-runtime Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pcattori pcattori marked this pull request as ready for review January 26, 2024 22:22
@pcattori pcattori mentioned this pull request Jan 26, 2024
@pcattori
Copy link
Contributor Author

pcattori commented Jan 29, 2024

Alternative would be to have something like:

  import {
-   LiveReload,
    Scripts,
    Outlet,
  }

  export default function App() {
    return (
      <html>
        <body>
-         <LiveReload />
           <Scripts />
          <Outlet />
        </body>
      </html>
    )
  }

Where <Scripts /> automatically includes dev scripts. For users who want to ship without JS, they can do <Scripts devOnly /> to still get the benefits of HMR/HDR in dev.

@pcattori
Copy link
Contributor Author

Superceded by #8636

@pcattori pcattori closed this Jan 31, 2024
@pcattori pcattori deleted the pedro/devscripts branch January 31, 2024 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants