-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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(ssr): skip rewriting stack trace if it's already rewritten (fixes #11037) #11070
fix(ssr): skip rewriting stack trace if it's already rewritten (fixes #11037) #11070
Conversation
await server.ssrLoadModule('/fixtures/modules/has-error.js') | ||
} catch (e) { | ||
expect(e[s]).toBe(true) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was passing before this PR but I added to ensure this won't break in future.
We added an option to avoid rewriting the stack trace awhile back, which is how we've dealt with this: #7046 |
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)
}
}) |
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. |
Description
See #11037 (comment) for the reason of this bug.
This PR will change
vite.ssrFixStacktrace
to 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'simport
by this cache.So I think we cannot change this part.
Making
ssrFixStacktrace
non-destructiveThe usage of
vite.ssrFixStacktrace
will 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
Error
instance.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).