Skip to content

Comments

fix cids_destroyed check using wrong selector#3981

Merged
SteffenDE merged 4 commits intomainfrom
sd-fix-cids-destroyed
Sep 4, 2025
Merged

fix cids_destroyed check using wrong selector#3981
SteffenDE merged 4 commits intomainfrom
sd-fix-cids-destroyed

Conversation

@SteffenDE
Copy link
Collaborator

Possibly closes #3979.

@SteffenDE SteffenDE merged commit 8a979c4 into main Sep 4, 2025
13 of 14 checks passed
@SteffenDE SteffenDE deleted the sd-fix-cids-destroyed branch September 4, 2025 16:24
SteffenDE added a commit that referenced this pull request Sep 4, 2025
* fix cids_destroyed check using wrong selector

Possibly closes #3979.

* fix same mistake again

* update test

* add e2e test
@DaTrader
Copy link

DaTrader commented Sep 9, 2025

@SteffenDE I'm perplexed by the implied meaning of the bug fix namin in the Changelog: Fix LiveComponents being destroyed when their DOM ID changes, even though they are still rendered .

A LiveComponent instance with all its server-side state should be discarded (as in replaced with a new one) when its DOM ID changes. I've been relying on this as probably the only sure way of achieving the said result.

Has this now been changed in any way?

@SteffenDE
Copy link
Collaborator Author

@DaTrader this should not have changed the actual behavior in any way. There are two mechanisms at play with LiveComponents:

  1. the DOM ID - this is the id attribute of the actual DOM node in the browser
  2. the LiveComponent id, which you pass to <.live_component>. This is used internally to assign the CID, the integer available as @myself and seen in the DOM as data-phx-component.

Most of the time, you pass the same ID to live_component as you also set on the DOM, but they don't actually need to be the same. Changing the DOM ID makes morphdom recreate the DOM nodes on the client, changing the LiveComponent ID replaces the LiveComponent on the server. The specific bug was encountered when changing the DOM ID only, but the actual LiveComponent (with same CID) was actually still being rendered.

@DaTrader
Copy link

DaTrader commented Sep 9, 2025

@SteffenDE Thanks for clarifying this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LiveView JS library code runtime error trying to access numeric property on null

2 participants