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

fix react refresh sourcemap in dev mode #1963

Closed
wants to merge 2 commits into from
Closed

fix react refresh sourcemap in dev mode #1963

wants to merge 2 commits into from

Conversation

magic-akari
Copy link

Changes

This PR will fix react refresh plugin source maps in dev mode.
related issue: #1213

Testing

  • plugins/plugin-react-refresh/test/plugin.test.js:
    add new reactRefreshOptions config option and remove mockBabel function.
  • test-dev:
    add react-source-map test files

Docs

bug fix only

@vercel
Copy link

vercel bot commented Dec 13, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/evxmawgtg
✅ Preview: https://snowpack-git-fork-magic-akari-fix-sourcemap-dev-mo-1e0d13.pikapkg.vercel.app

@magic-akari

This comment has been minimized.

@magic-akari
Copy link
Author

sokra github io_source-map-visualization_

Copy link
Contributor

@Xiot Xiot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I was just about to finish up my own PR to fix the sourcemap support.

@@ -0,0 +1,8 @@
/** React Refresh: Connect **/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spelling... reatc in this file and the next should be react

if (destBuildFile.code !== result) {
destBuildFile.map = undefined;
if (config.buildOptions.sourceMaps && (destExt === '.js' || destExt === '.css')) {
logger.warn(`source-map file not found in [${debugPath}]`, {name: step.name});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically you could still have inline sourcemaps which wouldn't have an external map

outputMap = await composeSourceMaps(filePath, destBuildFile.map, outputMap);
}
} else if (destExt === '.js' || destExt === '.css') {
logger.warn(`source-map file not found in [${debugPath}]`, {name: step.name});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about inline sourcemaps

outputMap = typeof map === 'object' ? JSON.stringify(map) : map;
if (destBuildFile.map) {
outputMap = await composeSourceMaps(filePath, destBuildFile.map, outputMap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the sourcemaps need to be composed?
I would assume that that since the plugin has access to the sourcemap, it would potentially compose the maps.

@davidwallacejackson
Copy link

Hey, just checking -- is this PR still alive? Really excited to try out Snowpack and TS sourcemap support is a blocker for me. Happy to pitch in if there's something I can do to get this over the finish line.

@magic-akari
Copy link
Author

@davidwallacejackson Sorry to reply so late. I'm still following this issue. There seems to be a lot of conflicts here. I will double check the conflicts a little later.

@FredKSchott
Copy link
Owner

Sorry @magic-akari, #2707 changed a lot of Snowpack internals. I'd actually love to help rebase this PR for you, if you don't mind waiting a little bit for me to make time.

@FredKSchott
Copy link
Owner

Okay, codebase has been refactored and is stable enough that rebasing this won't be a waste of time :) Appreciate everyones patience here.

@magic-akari if I rebase this for you onto main, are you still interested in getting it merged?

@magic-akari
Copy link
Author

Yes. Please rebase it.

@FredKSchott
Copy link
Owner

Alright, I attempted a rebase here: https://github.com/snowpackjs/snowpack/tree/fix-sourcemap-dev-mode-react-refresh

Unfortunately, quite a bit has changed. Normally git would be okay here, but the refactor included reorganizing files and moving logic around. This has made rebasing difficult.

What I might suggest instead is attempting to re-create this PR on top of main. As you go, it should become obvious where code has changed and hopefully obvious where it has moved to if it has moved. I think going line by line like this will be better than attempting to debug any unknown issues in a bad rebase.

Sorry again for the delay here.No pressure if you don't have the time to recreate: we appreciate the contribution regardless. I'm going to close this PR for now, but feel free to create a new PR or just ping me in this branch if you're able to get this updated and I can take another look.

@magic-akari magic-akari deleted the fix-sourcemap-dev-mode-react-refresh branch February 9, 2022 14:34
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.

4 participants