Skip to content

Hot module reloading (HMR) doesn't work if a page has no islands #3806

@brettchalupa

Description

@brettchalupa

Right now when I use deno run -Ar jsr:@fresh/init to generate a new Fresh site/app and remove all of the code generated (the Counter island, etc.) and just have a routes/index.tsx with some basic HTML, hot module reloading (HMR) breaks. The page does not auto-refresh when I make changes in my editor.

I see in the Fresh source that this is a TODO:

// TODO: Implement proper ssr hmr
options.server.hot.send("fresh:reload");

Temporary Fix

I found a workaround that does get it working:

diff --git a/routes/_app.tsx b/routes/_app.tsx
index 0225605..f00f73b 100644
--- a/routes/_app.tsx
+++ b/routes/_app.tsx
@@ -7,6 +7,9 @@ export default define.page(function App({ Component }) {
         <meta charset="utf-8" />
         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
         <title>My Fresh Site</title>
+        {import.meta.env.DEV && (
+          <script type="module" src="/@id/fresh:client-entry"></script>
+        )}
       </head>
       <body>
         <Component />

I'm not sure if that's appropriate as a long-term fix though. So I thought I'd open up this GitHub Issue.

It would be great if this just worked out of the box. Especially for server-side rendered apps that don't have any client-side code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions