codica2 / administrate-field-jsonb

A plugin to show and edit JSON objects within Administrate.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duplicated JSONEditor elements with Turbolinks

vijuarez opened this issue · comments

Hi,

I encountered an issue when using this gem. I'm building a project with Rails 6 and Turbolinks 5.2.1, which I sadly can't share at the moment. When I enter a page with an .administrate-jsoneditor or .administrate-jsoneditor-viewer element, the editor would load correctly, but ends up generating multiple copies once I leave and revisit the page.

I suspect that Turbolinks triggers the turbolinks:load event every time I visit the page, but also keeps the modified DOM between visits, generating multiple copies of the editor after repeated visits.

image

Sorry for not preparing an example showcasing the problem, but I'm short on time. I hacked together a workaround on this fork, which solves the problem by stopping the creation of a new editor if there's already one present. My solution is not robust at all and the commits were written on a hurry, so it would be better to consider an alternative fix.

Thanks!

Would it be possible to merge this? I am getting bitten by the same bug.