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

HMR does not work for JS files #191

Closed
7 tasks done
jprosevear opened this issue Jul 3, 2023 · 3 comments
Closed
7 tasks done

HMR does not work for JS files #191

jprosevear opened this issue Jul 3, 2023 · 3 comments

Comments

@jprosevear
Copy link

jprosevear commented Jul 3, 2023

Describe the bug

Using the jsx loader for js as files as per:
vitejs/vite#3448 (comment)

HMR does not work. Full page reloads happen instead.

Originally thought this might be solved by #188 (comment) but discussion there showed it was not.

This might be marked won't fix because Vite recommends the jsx/tsx extensions. However I thought it was worth a specific bug ticket even if its closed so there is a record of the decision.

Please note that create-react-app (where I'm porting from), nextjs and gatsby all support .js and this would help minimize the changes to port apps.

Reproduction

https://stackblitz.com/edit/vitejs-vite-p5o1nn?file=src%2FApp.js

Steps to reproduce

image (Changing something in App.js)

System Info

See stack blitz

Used Package Manager

npm

Logs

No response

Validations

@ArnaudBarre
Copy link
Member

ArnaudBarre commented Jul 3, 2023

This has been fixed in #188 I think.
Anyway this will not be better supported in Vite. esbuild, swc and bun agreed to not enable the JSX parser on JS files. Plus most codebases are now in TS and the extension is mandatory. Migrating now will simplify a lot the setup of future tools. There are plenty of one line command available on the gitst/stack overflow to migrate.

@ArnaudBarre ArnaudBarre closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2023
@jprosevear
Copy link
Author

This has been fixed in #188 I think. Anyway this will not be better supported in Vite. esbuild, swc and bun agreed to not enable the JSX parser on JS files. Plus most codebases are now in TS and the extension is mandatory. Migrating now will simplify a lot the setup of future tools. There are plenty of one line command available on the gitst/stack overflow to migrate.

It does not seem to have been fixed as per:
#188 (comment)
#188 (comment)

@jprosevear
Copy link
Author

@ArnaudBarre @csr632 vitejs/vite#3448 (comment) plus the unreleased version of this plugin solves the issue.

The fix in #188 is required so that the "react/jsx-dev-runtime" is used to set useFastRefresh correctly

 (isJSX ||
          (opts.jsxRuntime === 'classic'
            ? importReactRE.test(code)
            : code.includes(devRuntime)))

(code.includes in the correct order in the ternerary)

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

No branches or pull requests

2 participants