You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x-modelable/entangle() silently drops data for non-plain-object values (File, Map, Set, ...) via JSON round-trip clone #4873
x-modelable's entangle() clones the exposed value with JSON.parse(JSON.stringify(value)), which silently corrupts any value whose meaningful data lives on non-own or non-enumerable properties, File/FileList being the clearest real-world case since the platform exposes name/size/type through prototype getters rather than own enumerable properties. Filing this after confirming the mechanism in entangle.js and finding the documented $dispatch('input', ...) escape hatch, prompted by #4813.
After selecting files, files on the outer scope contains an array of plain objects with no own enumerable properties, {}-shaped in practice, instead of the real File instances innerFiles held. name/size/type are all gone.
Where it comes from
packages/alpinejs/src/entangle.js (permalink from the discussion, still true on main):
outer(getInner(),true)
backed by a JSON round-trip clone of whatever value crosses the entangle() boundary. JSON.stringify only serializes an object's own enumerable properties, and File's name/size/type/lastModified are inherited accessor properties defined on File.prototype, not own properties of the instance, so JSON.stringify(file) produces "{}" for any individual File, and the clone comes out empty.
Impact
Anyone building a custom form component (file pickers being the obvious case, but this applies to any non-plain-object value: Map, Set, class instances with getters, DOM nodes) and exposing it through x-modelable for x-model binding gets silent data loss with no error or warning, the outer scope's value looks populated (right array length, right shape) but every element is empty.
Possible directions
Document the limitation explicitly on the x-modelable page, right now it reads as a general-purpose two-way binding mechanism with no caveat about serializability.
Or, since the docs already document a lower-level alternative for exactly this ($dispatch('input', value), which x-model picks up via event.detail with no cloning involved), a runtime warning when entangle()'s JSON round-trip produces {} from a non-empty-looking source object would at least surface the failure instead of silently dropping data.
Activity
docs: clarify x-modelable value support (alpinejs#4880)