turbolinks / turbolinks-classic

Classic version of Turbolinks. Now deprecated in favor of Turbolinks 5.
MIT License
3.54k stars 431 forks source link

Make sure nested script tags are run when partial replacing #546

Closed kristianpd closed 9 years ago

kristianpd commented 9 years ago

We ran in to this recently on another project, TG change is here: https://github.com/Shopify/turbograft/pull/92

I haven't had a chance to test this on base TL but I want to make sure this is tracked in case we aren't.

kristianpd commented 9 years ago

/cc @Thibaut

Thibaut commented 9 years ago

Unlike Turbograft, Turbolinks 3 re-runs all scripts on the page on partial replacement. But I think it makes sense to only run those nested in the elements that have been swapped in, instead of all of them, now that we have data-turbolinks-eval=always (which we would also re-run).

I'll PR the change soon.

kristianpd commented 9 years ago

:+1: i'm fine for forcing people to be explicit with data-turbolinks-eval=always to help prevent weird inline JS problems. thanks @Thibaut

edlebert commented 9 years ago

It seems to currently run scripts in partials twice. If I have a script tag in a partial, and I say "Turbolinks.visit(url, { change: 'mypartial' }), scripts in 'mypartial' are evaluated twice. This only happens if I specify a 'change' option on visit.

Thibaut commented 9 years ago

Fixed by #618.