Skip to content

Add doc for another usage of "data-live-id" #815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

jcrombez
Copy link
Contributor

@jcrombez jcrombez commented Apr 20, 2023

Q A
Bug fix? no
New feature? no
License MIT

@weaverryan
Copy link
Member

After a bit more thinking, I'm going to close this in favor of #813. The issue you were having is not actually related to the smart component re-rendering system: it's just the classic "if you're looping over elements, you may need a data-live-id". In your case, if you have 3 <div> elements (let's call them A, B , C), and they are reordered (on the client side or on the server), to B, A, C, then when the component re-renders, it will actually:

  • Take div A and change it to have the contents of div B
  • Take div B and change it to have the contents of div A

The problem is that, if you have a Stimulus controller attached to each of these elements and you're storing some sort of state on the controller instance - e.g. this.isHighlighted = true, then suddenly your controller A instance will live on what appears to be the div B, and controller B instance will live on what appears to be the div A.

Anyways, thank you for bringing this up - you inspired the new docs there. If/when this bites people, we can continue to work on it.

@weaverryan weaverryan closed this Apr 20, 2023
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.

2 participants