Skip to content

Lazy loaded Arrayable props are no longer converted to array in v2.0Β #716

@netpok

Description

@netpok

In v2 Arrayable props are only converted to arrays if they are "regular" props. This happens because closures are resolved later than arrayable props: see here

IMHO this conversion should happen either on all forms of prop definition or never.

One solution would be to move resolveArrayableProperties after resolvePropertyInstances, this solves this issue but I did not test the effects on the whole system.


Backstory:

We use spatie media library in our project and passed the MediaCollection directly to the inertia view. After the v2 upgrade we noticed that ['propname' => $collection] and ['propname' => fn () => $collection] behaves differently.

This happens because

  • ['propname' => $collection] calls toArray because of the Arrayable check but
  • ['propname' => fn () => $collection] is not doing this so it will be fall back to toJson in the end which has a different implementation.

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