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: error overlay message escape #12305

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

florian-lefebvre
Copy link
Member

Copy link

changeset-bot bot commented Oct 25, 2024

🦋 Changeset detected

Latest commit: f6dc9c2

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Oct 25, 2024
this.text('#message-content', err.message, true);
// Only set as html if escaped. We're only sure it's escaped if name is part
// of the error, ie. we transformed it as we wanted.
// TODO: capture error at the source and transform it there
Copy link
Member Author

Choose a reason for hiding this comment

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

@Princesseuh I tried many things but couldn't find from where the error on initial render is coming. Basically the flow is as follow:

  1. you have failing code: escaped
  2. you update your failing code but it's still failing, you save
  3. on initial render, it's not escaped (the error has not been enhanced by us yet, where does it come from??)
  4. after 200ms, enhanced error is used (escaped)

@Princesseuh
Copy link
Member

I pushed an alternative fix, I'm not 100% sure of what I'm doing. It seems like on HMR upgrade, if any of the Vite processing thingy fails, Vite emits an error through the websocket that doesn't go through any of our usual error stuff. My method patches the .send method directly, but perhaps there's another way to do this properly? cc @bluwy

I'll note that Vite lose a lot of information from errors when doing this, so trying to enhance might not even be relevant in the first place as we can't achieve much.

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Fix looks good to me. Since any kind of errors can come through viteServer.hot.send(), as long as we normalize it to escape HTML, or handle it in the overlay code, it should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dev server error page: HTML in code comments gets rendered in error message (no escaping of <)
4 participants