Skip to content

x-modelable/entangle() silently drops data for non-plain-object values (File, Map, Set, ...) via JSON round-trip clone #4873

Closed

Description

@MILLERMARRU

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.

Repro

<div x-data="{ files: [] }">
  <div x-data="{ innerFiles: [] }" x-modelable="innerFiles" x-model="files">
    <input type="file" multiple
      @change="innerFiles = Array.from($event.target.files)" />
  </div>
</div>

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

  1. added a commit that references this issue on Aug 18, 2026
    5cab97b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions