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

feat(dev-server): transform HTML using Vite enabling HRM with official React plugin #142

Closed
wants to merge 1 commit into from

Conversation

gaetan-puleo
Copy link

vite react plugin add HMR support to vite. (Maybe other plugin do the same).

Today HMR is not working from component because Vite didn't transform the HTML.

This PR aim to fix this issue

Copy link

changeset-bot bot commented Jun 7, 2024

⚠️ No Changeset found

Latest commit: 924e9ae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@gaetan-puleo
Copy link
Author

This pr is fixing #141

@yusukebe
Copy link
Member

yusukebe commented Jun 7, 2024

Hi @gaetan-puleo

Thank you for the PR.

This change will break the case of a streaming response. So the Suspense like the following does not work with this PR.

import { Hono } from 'hono'
import { Suspense } from 'hono/jsx'
import { jsxRenderer } from 'hono/jsx-renderer'

export const renderer = jsxRenderer(
  ({ children }) => {
    return (
      <html>
        <body>{children}</body>
      </html>
    )
  },
  {
    stream: true
  }
)

const app = new Hono()

app.use(renderer)

const AsyncComponent = async () => {
  await new Promise((r) => setTimeout(r, 1000))
  return <h1>Hello!</h1>
}

app.get('/', (c) => {
  return c.render(
    <div>
      <h1>Streaming</h1>
      <Suspense fallback={'loading...'}>
        <AsyncComponent />
      </Suspense>
    </div>
  )
})

export default app

@gaetan-puleo
Copy link
Author

gaetan-puleo commented Jun 7, 2024

How can i fix this case? @yusukebe

I am not familiar with streaming

@yusukebe
Copy link
Member

yusukebe commented Jun 7, 2024

@gaetan-puleo
Copy link
Author

Yes it looks the same

@gaetan-puleo
Copy link
Author

@gaetan-puleo
Copy link
Author

I added this in my template on the server side and HMR is working now.

Maybe we can create a middleware or a plugin to inject those lines.

            {process.env.NODE_ENV === "development" && (
              <>
                <script
                  type="module"
                  dangerouslySetInnerHTML={{
                    __html: `
                  import RefreshRuntime from '${BASE_URL}/@react-refresh'
                  RefreshRuntime.injectIntoGlobalHook(window)
                  window.$RefreshReg$ = () => {}
                  window.$RefreshSig$ = () => (type) => type
                  window.__vite_plugin_react_preamble_installed__ = true
                  `,
                  }}
                />

                <script type="module" src="src/assets/main.tsx"></script>
              </>
            )}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants