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: don't invalidate when code is invalid #67

Merged
merged 1 commit into from Dec 19, 2022

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Dec 19, 2022

Description

import.meta.hot.accept(mod => {
  // mod is undefined when the code contains invalid syntax
  if (isReactRefreshBoundary(mod)) { // isReactRefreshBoundary(undefined) returns false
    ${timeout}
  } else {
    import.meta.hot.invalidate(); // this invalidate is called
  }
}

This PR adds if (!mod) return to fix invalidate happening.

This fixes vitejs/vite#11365.

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 p2-nice-to-have 🍰 Not breaking anything but nice to have (priority) p4-important ❗ Violate documented behavior or significantly improves performance (priority) feat: hmr and removed p2-nice-to-have 🍰 Not breaking anything but nice to have (priority) labels Dec 19, 2022
Copy link
Member

@ArnaudBarre ArnaudBarre left a comment

Choose a reason for hiding this comment

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

I have the same condition in react-swc plugin 👍

@patak-dev patak-dev merged commit 9231a86 into main Dec 19, 2022
@patak-dev patak-dev deleted the fix/dont-invalidate-when-code-is-invalid branch December 19, 2022 07:52
@EduardoLopes
Copy link

any date for next release with this fix?

@SamuelScheit
Copy link

@patak-dev we are also facing the same issue and waiting for a release, as manually installing this package from github doesn't work with a monorepo.

@Intevel
Copy link

Intevel commented Dec 30, 2022

Same here, would be great to see this released soon.

@ArnaudBarre
Copy link
Member

Available in 3.0.1!

@Intevel
Copy link

Intevel commented Jan 5, 2023

Thank you @ArnaudBarre

@SamuelScheit
Copy link

I still have the same issue vitejs/vite#11365 that vite gets stuck in an invalidating loop.
I've found a workaround by always using the isReactRefreshBoundary timeout function and commenting out import.meta.hot.invalidate().

@ArnaudBarre
Copy link
Member

ArnaudBarre commented Jan 6, 2023

I will check if it's still happening with #79

My advice is to stop doing barrels imports. Took me some hours when migrating from CRA, but that was worth it. Imports are not as beautiful, but with time you learn to don't care and IDE renaming/find usages & HMR works a lot better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: hmr p4-important ❗ Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vite 4.x Nested barrel imports cause infinite invalidating/hmr in certain conditions.
6 participants