-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Bug: Source maps don't work with hot reload #643
Comments
This is currently the expected behaviour, flagged as feature. This is quite hard with the current implementation of hot module reload |
We evaluate the new code with |
I've got this nearly working, but there is one oddity: eval(`console.log("test");
console.log("hello");
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6WyJjb25zb2xlIiwibG9nIl0sIm1hcHBpbmdzIjoiQUFFQUEsT0FBTyxDQUFDQyxHQUFSLENBQVksTUFBWjtBQUlBRCxPQUFPLENBQUNDLEdBQVIsQ0FBWSxPQUFaIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlc0NvbnRlbnQiOlsiXG5cbmNvbnNvbGUubG9nKFwidGVzdFwiKTtcblxuXG5cbmNvbnNvbGUubG9nKFwiaGVsbG9cIik7Il19`); correctly prints:
But hmr-runtime uses new Function(`console.log("test");
console.log("hello");
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNjcmlwdC5qcyJdLCJuYW1lcyI6WyJjb25zb2xlIiwibG9nIl0sIm1hcHBpbmdzIjoiQUFFQUEsT0FBTyxDQUFDQyxHQUFSLENBQVksTUFBWjtBQUlBRCxPQUFPLENBQUNDLEdBQVIsQ0FBWSxPQUFaIiwic291cmNlUm9vdCI6Ii4uIiwic291cmNlc0NvbnRlbnQiOlsiXG5cbmNvbnNvbGUubG9nKFwidGVzdFwiKTtcblxuXG5cbmNvbnNvbGUubG9nKFwiaGVsbG9cIik7Il19`)(); prints:
https://stackoverflow.com/a/49464959/2352201:
So TLDR:
😞 Correct code, but nowhere supported: https://github.com/parcel-bundler/parcel/tree/hmr-sourcemaps-v2 |
@mischnic do you think |
Continuing #5313 (comment)
Chrome supports this on a protocol level. Because it's supported there, we have already been able to use function sourcemaps in widely scenarios in VS Code and its JS debugger (for example, vscode has web worker extensions which are all invoked with new Function()). So if Parcel emitted sourcemaps in this scenario, Parcel users would be able to successfully debug using HMR in VS Code. And it puts a little pressure on the chrome devtools team to implement support for it within their UI 🙂 |
Neither of them actually show the correct line, but they do try to map something. WIP PR: #5316 |
Thanks for looking at this, let me know if you'd like me to lend a hand with anything 🙂 |
A workaround for the browser bugs would be somehow evaluating the new code via a |
Investigated this a bit. There are some challenges here. The situation hasn't changed much since @mischnic commented in 2019. Chrome and Firefox support let id = '_' + Math.random().toString(36).slice(4);
(0, eval)(`function ${id}(require, module, exports) {${asset.output}}`);
let fn = window[id];
delete window[id]; Unfortunately, while Safari seems to support this as well for I think the only option then would be to load a |
In the console I get an output like
index.jsx:6 "test1"
and that's okay.But when I save the file, it turns like
VM335:18 "test2"
.I have to refresh the page to see this one
index.jsx:6 "test2"
.So source maps don't work unless I refresh the page.
The text was updated successfully, but these errors were encountered: