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 next.js source map resolving #4062

Merged
merged 5 commits into from
Mar 9, 2023
Merged

fix next.js source map resolving #4062

merged 5 commits into from
Mar 9, 2023

Conversation

sokra
Copy link
Member

@sokra sokra commented Mar 3, 2023

Description

Before the error overlay didn't show the source mapped file.
Now it does.

  • The wrapped ContentSources need to wrap a Rewrite result.
  • Instead of returning a ContentSourceResult from a different ContentSource, one need to use Rewrite to get the data correct.

Testing Instructions

Throw an error in an next.js app that triggers the error overlay with stack trace.

@vercel
Copy link

vercel bot commented Mar 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
examples-tailwind-web 🔄 Building (Inspect) Visit Preview Mar 9, 2023 at 11:46AM (UTC)
examples-vite-web 🔄 Building (Inspect) Visit Preview Mar 9, 2023 at 11:46AM (UTC)
turbo-site ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 9, 2023 at 11:46AM (UTC)
7 Ignored Deployments
Name Status Preview Comments Updated
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Mar 9, 2023 at 11:46AM (UTC)
examples-cra-web ⬜️ Ignored (Inspect) Visit Preview Mar 9, 2023 at 11:46AM (UTC)
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Mar 9, 2023 at 11:46AM (UTC)
examples-kitchensink-blog ⬜️ Ignored (Inspect) Mar 9, 2023 at 11:46AM (UTC)
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Mar 9, 2023 at 11:46AM (UTC)
examples-nonmonorepo ⬜️ Ignored (Inspect) Mar 9, 2023 at 11:46AM (UTC)
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Mar 9, 2023 at 11:46AM (UTC)

@sokra sokra requested a review from jridgewell March 3, 2023 12:18
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

🟢 CI successful 🟢

Thanks

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

Benchmark for 7c95dbc

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 9112.43µs ± 42.46µs 9017.76µs ± 84.47µs -1.04%
bench_hmr_to_commit/Turbopack RCC/1000 modules 12.87ms ± 0.19ms 12.94ms ± 0.10ms +0.56%
bench_hmr_to_commit/Turbopack RSC/1000 modules 504.70ms ± 1.09ms 502.12ms ± 1.39ms -0.51%
bench_hmr_to_commit/Turbopack SSR/1000 modules 9325.96µs ± 44.18µs 9339.60µs ± 31.94µs +0.15%
bench_hmr_to_eval/Turbopack CSR/1000 modules 8037.12µs ± 33.02µs 8099.46µs ± 35.78µs +0.78%
bench_hmr_to_eval/Turbopack RCC/1000 modules 11.81ms ± 0.10ms 11.65ms ± 0.23ms -1.33%
bench_hmr_to_eval/Turbopack SSR/1000 modules 8219.14µs ± 48.08µs 8267.71µs ± 36.33µs +0.59%
bench_hydration/Turbopack RCC/1000 modules 3594.17ms ± 5.88ms 3596.65ms ± 7.90ms +0.07%
bench_hydration/Turbopack RSC/1000 modules 3216.80ms ± 10.26ms 3222.52ms ± 12.07ms +0.18%
bench_hydration/Turbopack SSR/1000 modules 3318.97ms ± 9.21ms 3298.97ms ± 7.32ms -0.60%
bench_startup/Turbopack CSR/1000 modules 2573.19ms ± 5.24ms 2585.04ms ± 12.58ms +0.46%
bench_startup/Turbopack RCC/1000 modules 2124.20ms ± 5.09ms 2134.40ms ± 4.84ms +0.48%
bench_startup/Turbopack RSC/1000 modules 2063.07ms ± 4.68ms 2060.99ms ± 6.20ms -0.10%
bench_startup/Turbopack SSR/1000 modules 2048.07ms ± 5.43ms 2044.69ms ± 3.00ms -0.16%

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2023

Benchmark for de72e6e

Click to view benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 9959.53µs ± 36.73µs 9882.88µs ± 37.36µs -0.77%
bench_hmr_to_commit/Turbopack RCC/1000 modules 12.37ms ± 0.07ms 12.39ms ± 0.13ms +0.16%
bench_hmr_to_commit/Turbopack RSC/1000 modules 524.62ms ± 1.22ms 526.22ms ± 1.29ms +0.30%
bench_hmr_to_commit/Turbopack SSR/1000 modules 10.16ms ± 0.02ms 10.13ms ± 0.05ms -0.28%
bench_hmr_to_eval/Turbopack CSR/1000 modules 8876.86µs ± 35.46µs 8889.97µs ± 34.46µs +0.15%
bench_hmr_to_eval/Turbopack RCC/1000 modules 11.26ms ± 0.10ms 11.30ms ± 0.08ms +0.36%
bench_hmr_to_eval/Turbopack SSR/1000 modules 9102.04µs ± 25.90µs 9044.03µs ± 53.48µs -0.64%
bench_hydration/Turbopack RCC/1000 modules 3778.32ms ± 15.40ms 3756.09ms ± 5.30ms -0.59%
bench_hydration/Turbopack RSC/1000 modules 3400.50ms ± 15.42ms 3379.52ms ± 10.12ms -0.62%
bench_hydration/Turbopack SSR/1000 modules 3460.78ms ± 10.29ms 3458.98ms ± 9.31ms -0.05%
bench_startup/Turbopack CSR/1000 modules 2683.77ms ± 7.01ms 2653.10ms ± 9.58ms -1.14%
bench_startup/Turbopack RCC/1000 modules 2216.26ms ± 4.92ms 2223.43ms ± 5.82ms +0.32%
bench_startup/Turbopack RSC/1000 modules 2148.40ms ± 4.70ms 2152.42ms ± 4.71ms +0.19%
bench_startup/Turbopack SSR/1000 modules 2151.38ms ± 2.94ms 2138.21ms ± 6.67ms -0.61%

@sokra sokra marked this pull request as ready for review March 4, 2023 06:51
@sokra sokra requested a review from a team as a code owner March 4, 2023 06:51
crates/turbopack-dev-server/src/source/source_maps.rs Outdated Show resolved Hide resolved
@@ -81,7 +78,15 @@ impl ContentSource for NextSourceMapTraceContentSource {
self_vc.await?.asset_source,
NextSourceMapTraceContentProcessorVc::new(id, line, column, frame.name).into(),
);
Ok(wrapped.as_content_source().get(path, Default::default()))
Ok(ContentSourceResultVc::exact(
ContentSourceContent::Rewrite(
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why these need to be rewrites. We're not expecting query params, right? We're not changing headers. This should be equivalent to just doing the .get() directly, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are changing the path, which is also reflected in the url in data.

@sokra sokra requested a review from alexkirsz March 9, 2023 12:24
@sokra sokra added the pr: automerge Kodiak will merge these automatically after checks pass label Mar 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

Benchmark for 44b8189

Test Base PR % Significant %
bench_hydration/Turbopack RCC/1000 modules 3584.95ms ± 12.77ms 3517.91ms ± 11.24ms -1.87% -0.53%
Click to view full benchmark
Test Base PR % Significant %
bench_hmr_to_commit/Turbopack CSR/1000 modules 9898.86µs ± 19.40µs 9968.56µs ± 36.49µs +0.70%
bench_hmr_to_commit/Turbopack RCC/1000 modules 11.49ms ± 0.08ms 11.48ms ± 0.08ms -0.08%
bench_hmr_to_commit/Turbopack RSC/1000 modules 535.79ms ± 1.23ms 539.76ms ± 2.45ms +0.74%
bench_hmr_to_commit/Turbopack SSR/1000 modules 10.21ms ± 0.04ms 10.11ms ± 0.07ms -0.95%
bench_hmr_to_eval/Turbopack CSR/1000 modules 9008.56µs ± 32.62µs 8956.97µs ± 40.83µs -0.57%
bench_hmr_to_eval/Turbopack RCC/1000 modules 10.64ms ± 0.07ms 10.56ms ± 0.12ms -0.67%
bench_hmr_to_eval/Turbopack SSR/1000 modules 9307.25µs ± 44.83µs 9296.22µs ± 38.27µs -0.12%
bench_hydration/Turbopack RCC/1000 modules 3584.95ms ± 12.77ms 3517.91ms ± 11.24ms -1.87% -0.53%
bench_hydration/Turbopack RSC/1000 modules 3207.45ms ± 10.02ms 3215.37ms ± 13.17ms +0.25%
bench_hydration/Turbopack SSR/1000 modules 3335.83ms ± 7.02ms 3339.21ms ± 8.64ms +0.10%
bench_startup/Turbopack CSR/1000 modules 2620.12ms ± 8.46ms 2611.84ms ± 15.52ms -0.32%
bench_startup/Turbopack RCC/1000 modules 2037.30ms ± 5.30ms 2028.69ms ± 4.22ms -0.42%
bench_startup/Turbopack RSC/1000 modules 2013.65ms ± 8.60ms 2002.45ms ± 6.26ms -0.56%
bench_startup/Turbopack SSR/1000 modules 2057.82ms ± 4.76ms 2048.97ms ± 2.55ms -0.43%

@@ -27,6 +27,7 @@ turbopack-core = { workspace = true }
turbopack-dev-server = { workspace = true }
turbopack-ecmascript = { workspace = true }
url = { workspace = true }
urlencoding = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
urlencoding = { workspace = true }

@@ -40,6 +42,17 @@ impl SourceMapContentSourceVc {
}
}

fn encode_pathname_to_url(pathname: &str) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment on why we need to encode the pieces between /s?

@kodiakhq kodiakhq bot merged commit d923d44 into main Mar 9, 2023
@kodiakhq kodiakhq bot deleted the sokra/fix-source-maps branch March 9, 2023 19:00
ijjk pushed a commit to vercel/next.js that referenced this pull request Mar 9, 2023
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 25, 2024
### Description

Before the error overlay didn't show the source mapped file.
Now it does.

* The wrapped ContentSources need to wrap a Rewrite result.
* Instead of returning a ContentSourceResult from a different
ContentSource, one need to use Rewrite to get the data correct.

### Testing Instructions

Throw an error in an next.js app that triggers the error overlay with
stack trace.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Jul 29, 2024
### Description

Before the error overlay didn't show the source mapped file.
Now it does.

* The wrapped ContentSources need to wrap a Rewrite result.
* Instead of returning a ContentSourceResult from a different
ContentSource, one need to use Rewrite to get the data correct.

### Testing Instructions

Throw an error in an next.js app that triggers the error overlay with
stack trace.
ForsakenHarmony pushed a commit to vercel/next.js that referenced this pull request Aug 1, 2024
### Description

Before the error overlay didn't show the source mapped file.
Now it does.

* The wrapped ContentSources need to wrap a Rewrite result.
* Instead of returning a ContentSourceResult from a different
ContentSource, one need to use Rewrite to get the data correct.

### Testing Instructions

Throw an error in an next.js app that triggers the error overlay with
stack trace.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: automerge Kodiak will merge these automatically after checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants