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

feat(client): close vite-error-overlay with Escape key #13795

Merged
merged 5 commits into from Jul 13, 2023

Conversation

chaejunlee
Copy link
Contributor

@chaejunlee chaejunlee commented Jul 12, 2023

Description

fixes #13748

Pressing esc key closes the error overlay.

I made sure to remove the EventListener after the overlay is closed.

Additional context

I added an 'keydown' EventListener to document.

Please let me know if it is inappropriate.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Jul 12, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@Henry-Hong
Copy link

Looking good.

@chaejunlee
Copy link
Contributor Author

While adding test, I found out that pressing Escape key doesn't close the overlay.

It was because of this object not directing to the correct object when passed as an addEventListener callback.

Therefore, I localized close function in order to remove the 'keydown' EventListener when the overlay is closed

packages/vite/src/client/overlay.ts Outdated Show resolved Hide resolved
packages/vite/src/client/overlay.ts Outdated Show resolved Hide resolved
@chaejunlee
Copy link
Contributor Author

@bluwy

I have put the close() back as the member function.

How I solved it was to assign (e => {...}).bind(this) to this.closeOnEsc().

Due to the fact that .bind(this) creates new function, document.addEventListener('keydown', this.closeOnEsc.bind(this)) makes it impossible to remove the keydown listener.

I've checked that setting this.closeOnEsc = (e) => {} fails on the test that I added.

@chaejunlee chaejunlee requested a review from bluwy July 12, 2023 09:08
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.

Looks great!

@chaejunlee
Copy link
Contributor Author

Thanks a lot for the approval! @bluwy

I don't think we can remove this, or it'll break:

function clearErrorOverlay() {
document
.querySelectorAll(overlayId)
.forEach((n) => (n as ErrorOverlay).close())
}

Regarding the code that you provided, I think there are no tests around handling the "message" events of WebSocket, especially 'update' and 'error'.

If that's the case, do you mind if I open a new issue and add some tests, after this PR?

@bluwy
Copy link
Member

bluwy commented Jul 13, 2023

For sure feel free to followup on that. We currently cover that part of the code in the hmr playground, so any additions to make it more robust is definitely appreciated.

Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

Nice! @bluwy do you think we can merge this in a patch? It is a new feature so the safest may be to add it to Vite 5 milestone.

@patak-dev patak-dev added feat: hmr p2-nice-to-have Not breaking anything but nice to have (priority) labels Jul 13, 2023
@bluwy
Copy link
Member

bluwy commented Jul 13, 2023

Yeah I think we can merge this as patch too. Was hoping to get another eye before merging.

@bluwy bluwy merged commit 85bdcda into vitejs:main Jul 13, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a close button to HMR overlay for screen reader accessibility
4 participants