-
-
Notifications
You must be signed in to change notification settings - Fork 383
[LiveComponent] Fix new URL calculation with LiveProp
using Serializer (and Serializer attributes), and when using custom modifier
#2988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,10 +69,10 @@ public function getOnlyPropsThatAcceptUpdatesFromParent(array $inputProps): arra | |
/** | ||
* @return UrlMapping[] | ||
*/ | ||
public function getAllUrlMappings(): iterable | ||
public function getAllUrlMappings(object $component): iterable | ||
{ | ||
$urlMappings = []; | ||
foreach ($this->livePropsMetadata as $livePropMetadata) { | ||
foreach ($this->getAllLivePropsMetadata($component) as $livePropMetadata) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the fix for the 2nd bug |
||
if ($livePropMetadata->urlMapping()) { | ||
$urlMappings[$livePropMetadata->getName()] = $livePropMetadata->urlMapping(); | ||
} | ||
|
@@ -81,7 +81,7 @@ public function getAllUrlMappings(): iterable | |
return $urlMappings; | ||
} | ||
|
||
public function hasQueryStringBindings($component): bool | ||
public function hasQueryStringBindings(object $component): bool | ||
{ | ||
foreach ($this->getAllLivePropsMetadata($component) as $livePropMetadata) { | ||
if ($livePropMetadata->urlMapping()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\UX\LiveComponent\Tests\Functional\EventListener; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\UX\LiveComponent\Tests\Fixtures\Dto\Address; | ||
use Symfony\UX\LiveComponent\Tests\LiveComponentTestHelper; | ||
use Zenstruck\Browser\Test\HasBrowser; | ||
|
||
|
@@ -26,17 +27,20 @@ public function getTestData(): iterable | |
'previousLocation' => null, | ||
'expectedLocation' => null, | ||
'props' => [], | ||
'args' => [], | ||
]; | ||
yield 'unknown_previous_location' => [ | ||
'previousLocation' => 'foo/bar', | ||
'expectedLocation' => null, | ||
'props' => [], | ||
'args' => [], | ||
]; | ||
|
||
yield 'no_prop' => [ | ||
'previousLocation' => '/route_with_prop/foo', | ||
'expectedLocation' => null, | ||
'props' => [], | ||
'args' => [], | ||
]; | ||
|
||
yield 'no_change' => [ | ||
|
@@ -45,52 +49,118 @@ public function getTestData(): iterable | |
'props' => [ | ||
'pathProp' => 'foo', | ||
], | ||
'args' => [], | ||
]; | ||
|
||
yield 'prop_changed' => [ | ||
yield 'path_prop_changed' => [ | ||
'previousLocation' => '/route_with_prop/foo', | ||
'expectedLocation' => '/route_with_prop/bar', | ||
'props' => [ | ||
'pathProp' => 'foo', | ||
], | ||
'updated' => [ | ||
'pathProp' => 'bar', | ||
'args' => [ | ||
'propName' => 'pathProp', | ||
'propValue' => 'bar', | ||
], | ||
]; | ||
|
||
yield 'alias_prop_changed' => [ | ||
yield 'path_alias_prop_changed' => [ | ||
'previousLocation' => '/route_with_alias_prop/foo', | ||
'expectedLocation' => '/route_with_alias_prop/bar', | ||
'props' => [ | ||
'pathPropWithAlias' => 'foo', | ||
], | ||
'updated' => [ | ||
'pathPropWithAlias' => 'bar', | ||
'args' => [ | ||
'propName' => 'pathPropWithAlias', | ||
'propValue' => 'bar', | ||
], | ||
]; | ||
|
||
yield 'query_alias_prop_changed' => [ | ||
'previousLocation' => '/', | ||
'expectedLocation' => '/?q=search%2Bterm', | ||
'props' => [], | ||
'args' => [ | ||
'propName' => 'boundPropWithAlias', | ||
'propValue' => 'search+term', | ||
], | ||
]; | ||
|
||
yield 'path_and_query_alias_prop_changed' => [ | ||
'previousLocation' => '/route_with_prop/foo', | ||
'expectedLocation' => '/route_with_prop/baz?q=foo+bar', | ||
'props' => [ | ||
'pathProp' => 'baz', | ||
], | ||
'args' => [ | ||
'propName' => 'boundPropWithAlias', | ||
'propValue' => 'foo bar', | ||
], | ||
]; | ||
|
||
$address = new Address(); | ||
$address->address = '123 Main St'; | ||
$address->city = 'Anytown'; | ||
yield 'with an object in query, keys "address" and "city" must be present' => [ | ||
'previousLocation' => '/', | ||
'expectedLocation' => '/?objectProp%5Baddress%5D=123+Main+St&objectProp%5Bcity%5D=Anytown&q=search', | ||
'props' => [ | ||
'objectProp' => $address, | ||
], | ||
'args' => [ | ||
'propName' => 'boundPropWithAlias', | ||
'propValue' => 'search', | ||
], | ||
]; | ||
|
||
$address = new Address(); | ||
$address->address = '123 Main St'; | ||
$address->city = 'Anytown'; | ||
yield 'with an object in query, with "useSerializerForHydration: true", keys "address" and "c" must be present' => [ | ||
'previousLocation' => '/', | ||
'expectedLocation' => '/?intProp=3&objectPropWithSerializerForHydration%5Baddress%5D=123+Main+St&objectPropWithSerializerForHydration%5Bc%5D=Anytown', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not easy to read, but the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw it would be nice if we could have a "clean" query, like it was done before. I tried to play with |
||
'props' => [ | ||
'objectPropWithSerializerForHydration' => $address, | ||
], | ||
'args' => [ | ||
'propName' => 'intProp', | ||
'propValue' => '3', | ||
], | ||
]; | ||
|
||
yield 'query with alias ("p") and modifier (prefix by "alias_")' => [ | ||
'previousLocation' => '/', | ||
'expectedLocation' => '/?alias_p=test', | ||
'props' => [ | ||
'propertyWithModifierAndAlias' => 'test', | ||
], | ||
'args' => [], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider getTestData | ||
*/ | ||
public function testNoHeader( | ||
public function testNewLiveUrlAfterLiveAction( | ||
?string $previousLocation, | ||
?string $expectedLocation, | ||
array $props, | ||
array $updated = [], | ||
array $args, | ||
): void { | ||
$component = $this->mountComponent('component_with_url_bound_props', $props); | ||
$dehydrated = $this->dehydrateComponent($component); | ||
|
||
$this->browser() | ||
->throwExceptions() | ||
->post( | ||
'/_components/component_with_url_bound_props', | ||
[] === $args | ||
? '/_components/component_with_url_bound_props' | ||
: '/_components/component_with_url_bound_props/updateLiveProp', | ||
[ | ||
'body' => [ | ||
'data' => json_encode([ | ||
'props' => $dehydrated->getProps(), | ||
'updated' => $updated, | ||
'args' => $args, | ||
]), | ||
], | ||
'headers' => [ | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for the first bug