-
Notifications
You must be signed in to change notification settings - Fork 20
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
Detect whether DOM has already been created #14
Comments
Hi, I don't know Turbolinks but I can take a look on your issue to see if you could share a working example on codepen.io or other online code editor. |
I studied your code a little more and I think I gained a deeper understanding of what is really happening now.
I locally edited the _init() {
// reset DOM (makes _init and _build idempotent)
const tagsInputContainer = this.element.previousSibling;
if (tagsInputContainer && tagsInputContainer.classList && tagsInputContainer.classList.contains('tags-input')) {
tagsInputContainer.parentNode.removeChild(tagsInputContainer);
this.element.style.display = 'inline';
}
// ...
} That's probably not he most effective way to make the DOM construction of Regarding the codepen demo, that is not that easy, because one needs actual browser navigation events to demonstrate the behavior. However, I prepared a test instance of my application to show case the behavior in a real-life environment. I know that it is not as concise as a minimal codepen example, but it might help to get a feeling for the behavior I'm describing. I appreciate if you take the time to have a look at it. Steps:
I realize this might be an edge case for your library but I'd still be interested in your opinion on this. |
Hi,
I'm desperately trying to get the tags input to work in combination with the Turbolinks framework. Turbolinks caches the DOM and restores the cached DOM on certain navigation events. That implies that the whole Javascript context persists accross page loads (App feels like an SPA)
When I attach the
BulmaTagsInput
usingnew BulmaTagsInput(someDOMElement)
, it will attach behavior and modify the element's DOM. This modified DOM is subsequently cached by the Turbolinks framework.Now, when Turbolinks restores a DOM from its cache, it restores the already prepared
BulmaTagsInput
DOM, but not the associatedBulmaTagsInput
instance that is required to manage the component's state. Thus I need to create a new instance ofBulmaTagsInput
which inevitably performs the DOM modifications again in its constructor and I end up with multiple artificial DOM elements.In order for this to work, the
BulmaTagsInput
would need to detect whether the required DOM elements have already been created and if so, opt put of creating them again. Or maybe you have some different ideas on how to get this to work?The text was updated successfully, but these errors were encountered: