Skip to content

[Autocomplete] Avoid destroying on disconnect #1219

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

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

weaverryan
Copy link
Member

Q A
Bug fix? yes
New feature? no
Tickets Fix #1204
License MIT

The tests pass - so I can't see a problem with NOT destroying the element.

@smnandre
Copy link
Member

so I can't see a problem with NOT destroying the element.

Is that not best practice in term of memory, Turbo compatibility, etc ?

If the controller creates the instance, it should handle the deletion too, no ?

Could Sortable mess with the Dom / create duplicates ?

@smnandre
Copy link
Member

The tests pass

Is there any test related to the disconnection ? 👼

@weaverryan
Copy link
Member Author

Indeed, destroying is a best practice. And looking at tom-select now, it DOES remove some event listeners (for me, removal of event listeners is the REAL important part of disconnect().

Sigh, in that case, maybe @rodnaph can create a reproducer so I can dive deeper into the underlying cause of why the value is lost?

@smnandre
Copy link
Member

I'm wondering if the cloning could conflict with stimulus... https://sortablejs.github.io/Sortable/#cloning

@smnandre
Copy link
Member

So, after many tests, there is indeed something we need to fix in our implementation...

...but it seems your solution could be a good fix in the meanwhile (pro/cons 100% favor).

WDYT to merge it and then open another issue to study why our implementation has hidden side-effets ?

@weaverryan weaverryan force-pushed the autocomplete-do-not-destroy branch from 4d90f32 to a57b2f9 Compare January 21, 2024 22:16
@weaverryan
Copy link
Member Author

This is ready to go. I kept the destroy(). The problem is that TomSelect.destroy() reverts the innerHTML of the <select>. This causes any value the user has selected to be lost. We restore it.

@weaverryan weaverryan force-pushed the autocomplete-do-not-destroy branch from ba13d56 to bcf6f2c Compare January 23, 2024 16:27
@weaverryan weaverryan merged commit 7ee0373 into symfony:2.x Jan 23, 2024
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.

[Autocomplete] SortableJS Sorting Issue
2 participants