Skip to content

[LiveComponent] LiveProp(url: true) does not accept urls #2900

Open
@norkunas

Description

@norkunas

From #2607 (comment)

I have this property on component:

    /**
     * @var array{r: array<string, true>, c: array<string, true>}
     */
    #[LiveProp(url: new UrlMapping('e'))]
    public array $expanded = ['r' => [], 'c' => []];

My url is /tree?expanded[r][C-D]=1 and now it does not properly hydrate because TypeHelper::accepts($type, $value) in QueryStringPropsExtractor::isValueTypeConsistent return false.

The problem I see is that both r and c in $expanded are set as optional: false:

Symfony\Component\TypeInfo\Type\ArrayShapeType {#5071 ▼
  -type: Symfony\Component\TypeInfo\Type\GenericType {#5157 ▼
    -variableTypes: array:2 [▼
      0 => Symfony\Component\TypeInfo\Type\BuiltinType {#5159 ▼
        -typeIdentifier: Symfony\Component\TypeInfo\TypeIdentifier {#5052 ▶}
      }
      1 => Symfony\Component\TypeInfo\Type\CollectionType {#5068 ▶}
    ]
    -type: Symfony\Component\TypeInfo\Type\BuiltinType {#5158 ▶}
  }
  -isList: false
  -shape: array:2 [▼
    "c" => array:2 [▼
      "type" => Symfony\Component\TypeInfo\Type\CollectionType {#5070 ▶}
      "optional" => false
    ]
    "r" => array:2 [▼
      "type" => Symfony\Component\TypeInfo\Type\CollectionType {#5068 ▶}
      "optional" => false
    ]
  ]
  -extraKeyType: null
  -extraValueType: null
}

So when it tries to set only r part this shape is not accepted anymore. This was previously working fine.
The functionality is simple:

  • I render a tree;
  • Clicking on first level entries saves state to $expanded = ['r' => ...];
  • Clicking on second level entries save state to $expanded = ['c' => ...];
  • Clicking is handling via two live actions which updates only r or c.

--

Tried to split into multiple properties:

    /**
     * @var array<string, true>
     */
    #[LiveProp(url: new UrlMapping('r'))]
    public array $expandedRoots = [];

    /**
     * @var array<string, true>
     */
    #[LiveProp(url: new UrlMapping('c'))]
    public array $expandedCategories = [];

still TypeHelper::accepts returns false on url /tree?r[A-B]=1&c[01713ef6-eced-7e20-ab12-008458caf697]=1

Originally posted by @norkunas in #2607 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions