You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered a problem in the project I’m working on, the overlay in the browser cause TypeError: Illegal constructor.
After investigation, I found that the overlay of Vite has defined a custom element ErrorOverlay, but before defining it, it will check whether the ErrorOverlay element has been defined. If it has been defined, it will skip the redefinition of the ErrorOverlay element. The key point is that although the declaration is skipped here, all the custom elements used in the subsequent code are the undefined ErrorOverlay elements here, which will cause the above error.
Here I hope to optimize the check for whether the ErrorOverlay element has been defined. I suggest two solutions: when it is detected that the ErrorOverlay element has been defined, replace the local ErrorOverlay element with the defined element, or disable the subsequent display of the ErrorOverlay element logic after printing a friendly error prompt.
As for why there are duplicate custom ErrorOverlay elements here, my specific scenario is that I use Vite for multiple projects and then integrate them into the same window context in a browser, which can be considered a micro-application scenario. This will lead to multiple vite client scripts being introduced.
I have solved this problem locally through a patch. The solution I used is to replace the locally defined elements with the declared custom elements.
Example:
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Describe the bug
I encountered a problem in the project I’m working on, the overlay in the browser cause TypeError: Illegal constructor.
After investigation, I found that the overlay of Vite has defined a custom element ErrorOverlay, but before defining it, it will check whether the ErrorOverlay element has been defined. If it has been defined, it will skip the redefinition of the ErrorOverlay element. The key point is that although the declaration is skipped here, all the custom elements used in the subsequent code are the undefined ErrorOverlay elements here, which will cause the above error.
Here I hope to optimize the check for whether the ErrorOverlay element has been defined. I suggest two solutions: when it is detected that the ErrorOverlay element has been defined, replace the local ErrorOverlay element with the defined element, or disable the subsequent display of the ErrorOverlay element logic after printing a friendly error prompt.
As for why there are duplicate custom ErrorOverlay elements here, my specific scenario is that I use Vite for multiple projects and then integrate them into the same window context in a browser, which can be considered a micro-application scenario. This will lead to multiple vite client scripts being introduced.
I have solved this problem locally through a patch. The solution I used is to replace the locally defined elements with the declared custom elements.
Example:
If you need me to provide a PR, please let me know.
Reproduction
https://stackblitz.com/edit/vitejs-vite-azzv3z?file=index.html
Steps to reproduce
see https://stackblitz.com/edit/vitejs-vite-azzv3z?file=index.html
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: