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

Wrong Source Map for js files in SSR mode #8657

Closed
7 tasks done
sheremet-va opened this issue Jun 19, 2022 · 4 comments · Fixed by #8997
Closed
7 tasks done

Wrong Source Map for js files in SSR mode #8657

sheremet-va opened this issue Jun 19, 2022 · 4 comments · Fixed by #8997
Labels
feat: ssr has workaround p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@sheremet-va
Copy link
Member

sheremet-va commented Jun 19, 2022

Describe the bug

When transforming JS files with server.transformRequest and enabled SSR flag, it returns invalid source map. sourceContent includes already processed import paths instead of the original ones.

To run code in reproduction:

node vite-repro.mjs

It was noticed in Vitest, because snapshots rely on source maps: vitest-dev/vitest#1376

Reproduction

https://stackblitz.com/edit/vitejs-vite-pacs84?file=vite-repro.mjs&view=editor

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red
Copy link
Member

It seems mappings field is correct (source-map-visualization). So to workaround just delete the incorrect sourcesContent field.

@sapphi-red sapphi-red added has workaround p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) and removed pending triage labels Jun 19, 2022
@sheremet-va
Copy link
Member Author

sheremet-va commented Jun 19, 2022

Why does it return a content then 🤔 I see there is no sourcesContent field for typescript files, for example 🤔

Thank you for the workaround!

@sheremet-va
Copy link
Member Author

sheremet-va commented Jun 19, 2022

I've managed to reproduce the error in Vitest with provided source map. I am not sure, where the error lies tho. Imagine, there are two files with the same content. One is js, the other is ts. When we try to access the same index, TS file returns correct one, but js returns incorrect one (one off). These indexes are coming from new Error().stack.

Reproduction:

https://stackblitz.com/edit/vitejs-vite-amcazy?file=tests%2Funit%2Futils%2Fdates.spec.ts,vite-repro.mjs,tests%2Funit%2Futils%2Fdates.spec.js

@sapphi-red
Copy link
Member

sapphi-red commented Jun 20, 2022

source-map-visualization (ts)

I think 80 is correct instead of 81 here.

-const jsPosition = consumerJs.originalPositionFor({ line: 10, column: 81 });
-const tsPosition = consumerTs.originalPositionFor({ line: 8, column: 81 });
+const jsPosition = consumerJs.originalPositionFor({ line: 10, column: 80 });
+const tsPosition = consumerTs.originalPositionFor({ line: 8, column: 80 });

Why ts returns the same value with 80 and 81 is because it points the same segment.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: ssr has workaround p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants