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(hmr): duplicate link tags #9697

Merged
merged 2 commits into from Aug 16, 2022
Merged

fix(hmr): duplicate link tags #9697

merged 2 commits into from Aug 16, 2022

Conversation

xieyhn
Copy link
Contributor

@xieyhn xieyhn commented Aug 16, 2022

Description

Fix: duplicate link tags will be generated when the style file is edited and saved too frequently.

The bug occurred when a new message push was received before the newLinkTag callback responded.

Additional context


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 Commit 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.

@sapphi-red sapphi-red added feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority) labels Aug 16, 2022
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thanks! I've tested by throttling network and it actually fixed the bug. Some nitpicks but the behavior looks good to me.

@@ -126,6 +126,7 @@ function cleanUrl(pathname: string): string {
}

let isFirstUpdate = true
const invalidLinkTags = new Set<HTMLLinkElement>()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could use WeakSet to be safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm..., I'm not sure about the client code's browser support

Copy link
Member

Choose a reason for hiding this comment

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

We are transpiling client code to es2019. So I believe it's fine.

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

xieyhn commented Aug 16, 2022

It's easier to reproduce in my recent development, so I created this PR ~

@sapphi-red sapphi-red changed the title fix(hmr): Duplicate link tags fix(hmr): duplicate link tags Aug 16, 2022
@patak-dev patak-dev merged commit 9aa9515 into vitejs:main Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants