Repository navigation
fix(vite): normalise development ssr app stacktrace - #33989
Conversation
|
|
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
Merging this PR will not alter performance
Comparing Footnotes
|
|
@danielroe test are throwing i'll fix it later. Do you think we could open a PR to vite to allow calling
|
|
the ideal scenario is that we implement this entirely in the vite-builder package (or upstream in vite or vite-node) as it sounds like it is entirely an artifact of the vite node dev server implementation we have do you think that's possible? |
|
Just looked at vite-node. The fix should probably done here. I think i'll try to work on it. Once merged, this PR could get a rework to use the exposed |
f1fb2d6 to
a483570
Compare
|
OK so let's add a |
6919fcf to
2fc6d57
Compare
ca78ae4 to
577cb6f
Compare
|
@danielroe is there a reason we don't allow importing anything from vite-builder in nitro ? I think it should be OK. |
|
it's not a dependency of nitro and it should be conceptually separate - it helps us build good abstractions internally. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/vite/src/fix-stacktrace.ts (1)
5-11: Model the runner cache as optional for type accuracy.At runtime,
runneris unset until Line 10. Declaring that explicitly improves type safety for future edits.Suggested diff
- let runner: ViteNodeRunner + let runner: ViteNodeRunner | undefined🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/vite/src/fix-stacktrace.ts` around lines 5 - 11, The runner variable should be typed as optional to reflect that it's unset at startup; change the declaration of runner to allow undefined (e.g., let runner: ViteNodeRunner | undefined) and keep the lazy import in nitroApp.hooks.hook('error', ...) using the existing runner ||= await import(...) pattern and the subsequent call to runner.ssrFixStacktrace(error) (or use optional chaining runner?.ssrFixStacktrace(error) if you prefer to guard the call) so TypeScript knows the cache may be undefined until initialized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/vite/src/fix-stacktrace.ts`:
- Around line 5-11: The runner variable should be typed as optional to reflect
that it's unset at startup; change the declaration of runner to allow undefined
(e.g., let runner: ViteNodeRunner | undefined) and keep the lazy import in
nitroApp.hooks.hook('error', ...) using the existing runner ||= await
import(...) pattern and the subsequent call to runner.ssrFixStacktrace(error)
(or use optional chaining runner?.ssrFixStacktrace(error) if you prefer to guard
the call) so TypeScript knows the cache may be undefined until initialized.
ℹ️ Review info
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/vite/build.config.tspackages/vite/src/fix-stacktrace.tspackages/vite/src/vite.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/vite/src/vite.ts
- packages/vite/build.config.ts
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Roe <[email protected]>
🔗 Linked issue
fix #33917
📚 Description
This PR fixes stacktraces for errors triggered within the vue application in SSR.
The issue lies in vite which uses an offset and the error coming from nitro which has no offset on the stack traces lines. This offset causes vite's
ssrFixStacktraceto not be able to correctly get the position of the error from sourcemaps.Not sure whether this should be fixed within Nuxt or if Vite should provide a way to trigger
ssrFixStacktracewithout offset.We could also implement an utility to retrieve sourcemap from the vite runner and fix the stacktrace on nuxt's side instead of add an offset and calling
ssrFixStacktracefrom vite.