joist icon indicating copy to clipboard operation
joist copied to clipboard

When replacing elements, disconnect is called after connect

Open Phoscur opened this issue 5 months ago • 3 comments

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:

  1. Checkout and install https://github.com/Phoscur/joist-vite
  2. Run npm start and open localhost:4200
  3. Click the button to trigger the HTMLElement replacement (toggle the language)
  4. 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

Image

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.

Phoscur avatar Jul 24 '25 15:07 Phoscur

@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?!

Phoscur avatar Jul 25 '25 17:07 Phoscur

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

Phoscur avatar Jul 27 '25 18:07 Phoscur

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

Phoscur avatar Jul 31 '25 19:07 Phoscur