core
core copied to clipboard
fix(custom-element): properly handle custom element remove then insert again
close https://github.com/vuejs/core/issues/12412
~~changes:~~ ~~- extract observer code~~ ~~- observe again and re-mount if it's resolved and no instance, new parent will be set on new mount~~ ~~- exposed properties should be configurable, and we should delete them if element is fully unmounted, so that we can expose again in new mount~~
~~changes:~~ ~~- extract unmount code, delete exposed properties when unmounting, clear parent and set resolved to false~~ ~~- unmount if parent changed when connected~~ ~~- delete invalid exposed key from exposed when mounting~~
changes:
- extract observer code
- extract unmount code, delete exposed properties when unmounting, clear parent
- unmount if parent changed in connectedCallback and then re-mount
- observe again and re-mount if it's resolved and no instance, new parent will be set on new mount
- delete invalid exposed key from exposed when mounting
Summary by CodeRabbit
- Bug Fixes
- Improved handling of custom elements when moved or removed from the DOM, ensuring correct updates and style management without errors.
- Tests
- Added new tests to verify custom element behavior during DOM removal, re-attachment, and parent changes, ensuring proper context and style updates.
- Refactor
- Streamlined internal logic for mounting, unmounting, and observing custom elements to enhance reliability and maintainability.