Skip to content

Conversation

@nwidynski
Copy link

Description

This PR marks /@react-refresh as a virtual module to avoid false positive "missing source" warnings.

@nwidynski nwidynski changed the title Patch 1 fix: avoid missing source warnings for react-refresh Apr 21, 2025
@sapphi-red
Copy link
Member

sapphi-red commented Apr 22, 2025

Could you provide a reproduction when this is needed?

@nwidynski
Copy link
Author

@sapphi-red Do you happen to have a default sandbox template I can use for reproduction?

@sapphi-red
Copy link
Member

@nwidynski You can use http://vite.new/react-ts

@nwidynski
Copy link
Author

nwidynski commented Apr 22, 2025

@sapphi-red https://stackblitz.com/edit/vitest-tests-browser-examples-7wxz6en1

This one works, although you need to download and execute it locally. Stackblitz has troubles spawning a headless browser. Just run vitest and you will see the warning pop up.

@sapphi-red
Copy link
Member

OK. I understand the root cause. The ideal fix is to inject the source at

_getCombinedSourcemap(): SourceMap | { mappings: '' } | null {

when inputMap does not exist. injectSourcesContent should not be needed if that's done.

@nwidynski
Copy link
Author

@sapphi-red Like this?

if (sm.sources.length === 1 && !sm.sources[0] || !this.originalSourcemap) {
  combinedMap = {
    ...sm,
    sources: [this.filename],
    sourcesContent: [this.originalCode],
  }
}

@sapphi-red
Copy link
Member

I think something like that. I haven't checked why that part is not running though.

@ArnaudBarre
Copy link
Member

ArnaudBarre commented May 17, 2025

This is a bug in the SWC plugin, fixed in vitejs/vite-plugin-react#478

@nwidynski nwidynski closed this May 17, 2025
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