Skip to content

Stop core clone() from reaching for a global jQuery/Zepto - #2476

Open
afonsojanu wants to merge 1 commit into
SortableJS:masterfrom
afonsojanu:fix/core-clone-avoid-implicit-jquery-detection
Open

Stop core clone() from reaching for a global jQuery/Zepto#2476
afonsojanu wants to merge 1 commit into
SortableJS:masterfrom
afonsojanu:fix/core-clone-avoid-implicit-jquery-detection

Conversation

@afonsojanu

Copy link
Copy Markdown

Fixes #2453.

clone() in src/utils.js checked window.jQuery and window.Zepto and used their clone() whenever either happened to be present on the page, no matter whether jquery-sortablejs was the thing actually driving the widget. So a page that loads jQuery for something completely unrelated, but uses plain SortableJS directly, would silently get routed through jQuery's clone instead of a native cloneNode. The linked issue shows exactly this: a non-jQuery global that merely calls itself jQuery breaks the whole thing since it doesn't implement clone() the way real jQuery does.

I went and checked the jquery-sortablejs package itself to make sure removing this wouldn't quietly break it: it's a thin $.fn wrapper around Sortable, it never calls into or depends on this clone() function reaching for jQuery internally. So there's no real coupling here, core doesn't need the jQuery/Zepto branch at all, and cloneNode is the right default the same way it already is when neither is present.

I couldn't run the existing TestCafe suite in my environment (no screen-recording permission on this machine, which TestCafe's browser-tools needs even in headless mode on macOS), so instead I wrote a small standalone Node script that loads the built UMD bundle with a stubbed window/document and a fake jQuery-like global matching the issue's repro, and confirmed the old code throws trying to call the fake global's clone(), while the patched version correctly falls through to cloneNode. Happy to share that script if useful, just didn't want to add throwaway test infra to the PR itself.

clone() checked window.jQuery and window.Zepto and used their clone
method whenever either happened to exist on the page, regardless of
whether jquery-sortablejs was actually the thing driving Sortable.
That means any page with jQuery loaded for unrelated reasons, but
using plain SortableJS directly, silently got jQuery's clone instead
of a native cloneNode, which breaks in interesting ways if that
jQuery-like global doesn't behave exactly like real jQuery.

Checked jquery-sortablejs itself: it never touches this function or
relies on it reaching for jQuery internally, it just wraps Sortable in
a $.fn plugin. So core has no real reason to special-case jQuery here
at all, native cloneNode is what it should use unless something more
specific (Polymer, in this file) says otherwise.

Fixes SortableJSGH-2453.
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.

[bug] Core clone util uses JQuery without jquery-sortablejs installed

1 participant