When replacing elements, disconnect is called after connect
Describe the bug Somehow tests concerning injectable elements are not covering actual behavior in the browser.
I've trimmed my usecase for the reproduction, but I would not call it minimal (yet). Hopefully it is good enough to explore the issue further.
To Reproduce Steps to reproduce the behavior:
- Checkout and install https://github.com/Phoscur/joist-vite
- Run
npm startand open localhost:4200 - Click the button to trigger the HTMLElement replacement (toggle the language)
- See error/logs in the browser console: Zeitgeber protects itself from being started without getting stopped first
Expected behavior Elements being replaced should disconnect first, before the new ones connect
Screenshots
Desktop (please complete the following information):
- OS: Windows
- Browser: Chromium
- Version: 120
Additional context Split from #1265, it's not @joist/di version dependent. In a more convoluted usecase on @joist/di version 3, it doesn't reconnect multiple times and rather creates additional Zeitgebers - that remains as a separate issue, and I'm not sure if I'll chase that one down.
@deebloo I have a feeling this is what is to be expected. First the HTMLElements are rendered and then they replace the old ones, and that will trigger disconnect and destruction. Not sure if it's worth trying to reproduce this in unit tests (with JSDOM).
How do I handle my use case now? I guess I should not care about stopping "Zeitgeber" at all?!
Mh. Okay I believe I will go with triggering the clean up (stop Zeitgeber) procedure already in the connectedCallback, so it will be
0. pre connect: clean up or inform dependencies to reset
1. connect
2. don't rely on disconnect
Not sure what we should do concering the unit tests, they are definately not telling the right story at the moment...
Oh wow, console.log is not even reliable concerning browsers here... I notice Firefox will actually post the "Zeit Ctx disconnected" before the error... consistently.
In meanwhile I found another issue with DOMInjector...