fix(ssr): skip rewriting stack trace if it's already rewritten (fixes #11037)#11070
Merged
patak-cat merged 4 commits intovitejs:mainfrom Dec 8, 2022
Merged
Conversation
sapphi-red
commented
Nov 25, 2022
| await server.ssrLoadModule('/fixtures/modules/has-error.js') | ||
| } catch (e) { | ||
| expect(e[s]).toBe(true) | ||
| } |
Member
Author
There was a problem hiding this comment.
This test was passing before this PR but I added to ensure this won't break in future.
Collaborator
|
We added an option to avoid rewriting the stack trace awhile back, which is how we've dealt with this: #7046 |
Member
Author
|
The repro of #11037 uses that option. app.use('*', async (req, res) => {
try {
const render = (await vite.ssrLoadModule('/src/entry-server.js')).render // fixStacktrace is `false` by default
const url = req.originalUrl.replace(base, '')
const rendered = await render(url, ssrManifest)
res.status(200).set({ 'Content-Type': 'text/html' }).end(rendered)
} catch (e) {
vite?.ssrFixStacktrace(e)
console.log(e.stack)
res.status(500).end(e.stack)
}
})Does SvelteKit do it like this to avoid #11037? const rewroteErrors = new WeakSet()
app.use('*', async (req, res) => {
try {
const render = (await vite.ssrLoadModule('/src/entry-server.js')).render // fixStacktrace is `false` by default
const url = req.originalUrl.replace(base, '')
const rendered = await render(url, ssrManifest)
res.status(200).set({ 'Content-Type': 'text/html' }).end(rendered)
} catch (e) {
if (!rewroteErrors.has(e)) {
vite?.ssrFixStacktrace(e)
rewroteErrors.add(e)
}
console.log(e.stack)
res.status(500).end(e.stack)
}
}) |
bluwy
previously approved these changes
Nov 29, 2022
Member
I don't think so, but I also haven't heard of this happening in SvelteKit. But I think it's good that we fix this generically though so that it always works. |
patak-cat
reviewed
Dec 8, 2022
patak-cat
approved these changes
Dec 8, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
See #11037 (comment) for the reason of this bug.
This PR will change
vite.ssrFixStacktraceto work like: After rewriting stack trace, add a property to indicate that. If the error included that property, skip rewriting stack trace.fixes #11037
Additional context
I considered the following alternatives.
Changing the error cache
By running this script, you can see the error instance is same between both imports.
Vite's
ssrLoadModule's semantics aligns with Node.js'simportby this cache.So I think we cannot change this part.
Making
ssrFixStacktracenon-destructiveThe usage of
vite.ssrFixStacktracewill be like:This will be a breaking change. We could introduce a new method, but that will still require users to change the code to avoid #11037 happening.
Also I didn't find a good way to clone
Errorinstance.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).