-
-
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
feat: runtime error overlay #6274
base: main
Are you sure you want to change the base?
Conversation
got them fixed |
561411c
to
2cf71fc
Compare
updated demo showing off promise rejection and more test cases vite.runtime.overlay.draft.v2.mp4as a fun aside I was enjoying having a runtime overlay while developing the overlay.. anytime I broke something the overlay would fire and show me what i broke, |
const RE_CHROME_STACKTRACE = | ||
/^ {4}at (?:(.+?)\s+)?\(?(.+?)(?::(\d+))?(?::(\d+))?\)?$/ | ||
const RE_FIREFOX_STACKTRACE = | ||
/^(?:(?:(^|.+?)@))\(?(.+?)(?::(\d+))?(?::(\d+))?\)?$/ |
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.
These feel a bit messy to me but they work. if someone wants to take a crack at making this cleaner i would appreciate it
if (!fileRE.test(text)) { | ||
el.textContent = text | ||
return | ||
} else { | ||
fileRE.lastIndex = 0 | ||
} |
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 was added to support none link stack frames like a non-error was thrown please check your browser's devtools for more information
this kinda feels hacky. would love any suggestions on how this should be handled
} | ||
} | ||
|
||
// TODO: add support for url source maps |
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.
Does vite even emit url sourcemaps in dev?
@@ -40,14 +40,16 @@ const clientConfig = { | |||
input: path.resolve(__dirname, 'src/client/client.ts'), | |||
external: ['./env', '@vite/env'], | |||
plugins: [ | |||
nodeResolve(), |
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.
Opening the door for dependencies (bundling) in client.mjs feels a bit risky.
Simply bundling source-map makes client.mjs grow from 17k to 127k.
@@ -0,0 +1,266 @@ | |||
import type { RawSourceMap } from 'source-map' | |||
import { SourceMapConsumer } from 'source-map' |
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.
Using source-map in browser seems a bit risky, 0.6 works fine but 0.7 introduced a wasm dependency, and 0.8 (beta) introduces a 300k whatwg-url one.
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 method could probably be used when we have moved over to source-map-js
sourceMapConsumer?: SourceMapConsumer | ||
baseSource: string | ||
}> => { | ||
const source = await (await fetch(fileName)).text() |
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.
Pretty clever way to get the source map for the file
Though if we consider that we're going to fetch something from vite server anyway, what about sending the error to the server for normalization instead (e.g. through the WS link: socket.send({ type: 'runtime-error', error})
) ?
That'd avoid duplicating the work (normalizing errors in vite server & doing it also in vite client) and would also limit the use of dependencies in the client.
My 2c
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.
Yea i agree, it would make more sense to use the websocket connection and move the processing over to the server.
Hey @arbassett, sorry for don't get back to you on this one. Now that 2.9 is out, we are starting to prepare for Vite 3.0, and this could be an interesting feature to have in the next Vite major in case you or someone else is interested in keep working on this. When we talked with the team about this PR, we discussed that:
Another idea, since we have a good client server API maybe we should first check if an external plugin is possible (maybe with some smaller changes or APIs in core). Having it in core could still be the way to go.
This is interesting, maybe we could check how other build tools handle this?
I think we should go with the second option, requiring multiple clicks could be quite bad for some projects.
I think we could start without these. |
@patak-dev thanks for getting back to me on the questions. I'm hoping I will have some more time to work on this feature when work dies down.. but if anyone feels like they want to pick it up before I get a chance feel free.
when I saw the work starting on this I figured its better to wait until its done as its basically what was suggested.
I think this is the right way to go. at the very least it should allow faster prototyping
do we have a preference on what colour. I'm not super keen on yellow (warning) or green (everything is good). maybe something thats not used to often like purple/violet |
Nice, yes, modifying core is a lot more involved. If this could be an external plugin for some time, we may be able to move quicker, get users and feedback, and then at one point we could add it built in if that makes sense.
Yes, I was also thinking about that tones. We could also add a label to make it more clear. IMO, we also don't need to be constrained by the current overlay design here. Maybe for runtime errors, it makes more sense to have something less intrusive? For a Vite error, we normally want to cover the screen, but for runtime errors, maybe the UI is functional? And we could use temporal toasts that don't block the UI? Just an idea, but we could play with a DX that is more fit to each error type. |
+1 for toasts too, otherwise we may get similar request like vercel/next.js#13387 |
This is very good work! Any idea when this gets merged? |
Is there a way to use it without maintaining forked vite? |
Description
Fixes #2076
To add support for runtime error overlays using vites built in overlay.
it is currently possible to use
create-react-app
's react-error-overlay in vite but this experience is subpar to how server errors are currently handledAdditional context
This works as a base impetration but i would love to get some feedback on potential addition features and unknowns.
import.meta.error
vite.runtime.overlay.draft.mp4
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).