-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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 #3002
Comments
Could you create a small reproducible repo, that will help other contributors to jump straight into the issue and may provide help faster 🙂 It's really hard to look into that many images that are oversized and it's not possible to copy text from them |
The cache may cause the problem.? |
I had the same problem,HRM not work |
see this:#2968 I encountered the problem you mentioned, because we use whistle. the websocket connection failed and caused the reswiping. .You can solve this problem through the following configuration. |
ok. I will sort it out.thx!! |
thx! it works! |
but ennnn. Do you have the same promblem(hmr does not work) just like me?or maybe you are not here yet? |
sorry i do not have the problem you mentioned.but do you define the entrance of the project in vite.config.ts correctly? because you change the App.tsx to Index.tsx. you can open the chrome devtool to see the whether the <script> in html is the right file |
I am also seeing the same issue and created this repository that reproduces with minimal changes. https://github.com/uptownhr/vite-vue-jsx-hmr-error |
I debugged your codes for reproduction and found that when As a workaround, you can define your component like this I think the problem is not the same as yours. @uptownhr I tested on the official export default defineConfig({
server: {
hmr: {
protocol: 'ws',
host: 'localhost'
}
},
plugins: [reactRefresh()]
}) whistle:
|
@Sociosarbis Sociosarbis the problem is not the same as my. |
@Shinigami92 @Sociosarbis need I provide a small reproducible repo? repo:https://github.com/xiaomuzizier/hmr-react-error-repo |
@ygj6 Take a look now |
My problem has been solved . HRM not work reason : when i use ts in project , run |
@JinJieTan I find the problem.like this: vitejs/vite-plugin-react#20 When I implemented the repo, I found that when I used dynamic loading, it would cause hmr fail. If I do not use dynamic loading in the routing, hmr will take effect. the repo is :https://github.com/xiaomuzizier/hmr-react-error-repo |
There is nothing to do with dynamic loading and the real reason let HMR not work is react-refresh doen't support old-style class component. The workaround is rewriting your component to functional component. Here is the result.
import React from 'react';
export default class Test extends React.Component {
state = {};
render() {
return <h1>hi</h1>;
}
}
import __vite__cjsImport0_react from "/node_modules/.vite/react.js?v=04f53729"; const React = __vite__cjsImport0_react.__esModule ? __vite__cjsImport0_react.default : __vite__cjsImport0_react;
export default class Test extends React.Component {
constructor() {
super(...arguments);
this.state = {};
}
render() {
return /* @__PURE__ */ React.createElement("h1", null, "hi");
}
} after rewriting: import React from 'react';
export default function Test() {
return <h1>hi</h1>;
} compiled import { createHotContext as __vite__createHotContext } from "/@vite/client";import.meta.hot = __vite__createHotContext("/src/components/Test.tsx");import RefreshRuntime from "/@react-refresh";
let prevRefreshReg;
let prevRefreshSig;
if (!window.__vite_plugin_react_preamble_installed__) {
throw new Error("vite-plugin-react can't detect preamble. Something is wrong. See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201");
}
if (import.meta.hot) {
prevRefreshReg = window.$RefreshReg$;
prevRefreshSig = window.$RefreshSig$;
window.$RefreshReg$ = (type, id) => {
RefreshRuntime.register(type, "D:/sociosarbis-projects/hmr-react-error-repo/src/components/Test.tsx " + id);
};
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
}
var _jsxFileName = "D:\\sociosarbis-projects\\hmr-react-error-repo\\src\\components\\Test.tsx";
import __vite__cjsImport2_react from "/node_modules/.vite/react.js?v=04f53729"; const React = __vite__cjsImport2_react.__esModule ? __vite__cjsImport2_react.default : __vite__cjsImport2_react;
export default function Test() {
return /* @__PURE__ */ React.createElement("h1", {
__self: this,
__source: {
fileName: _jsxFileName,
lineNumber: 6,
columnNumber: 10
}
}, "hi");
}
_c = Test;
var _c;
$RefreshReg$(_c, "Test");
if (import.meta.hot) {
window.$RefreshReg$ = prevRefreshReg;
window.$RefreshSig$ = prevRefreshSig;
import.meta.hot.accept();
if (!window.__vite_plugin_react_timeout) {
window.__vite_plugin_react_timeout = setTimeout(() => {
window.__vite_plugin_react_timeout = 0;
RefreshRuntime.performReactRefresh();
}, 30);
}
} |
oh。@Sociosarbis thx! I got it. so @Shinigami92 , can "react-refresh" support old-style class component? |
I think we can close this issue @xiaomuzizier, as @Sociosarbis explained, this could be a request for the react fast refresh team. |
ok,thx! |
Describe the bug
I see this HMR didn't work for dynamic imported modules ,I also have this issue.
but I have another problem in react.
for example:
my vit config:
my whistle:
I will use "cms.fcc.qq.com" open the page.
my html:
my component:
index.tsx use App.tsx:
App.tsx:
when I change something in GLHeaderMenu component.
this will show '[vite] hmr update /src/App.tsx' .the page does not update
hmr does not work .
Reproduction
System Info
Output of
npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:Used package manager:
Logs
Before submitting the issue, please make sure you do the following
The text was updated successfully, but these errors were encountered: