Skip to content

Commit 18fb8a0

Browse files
committed
[Live] Reverting back to simpler serialize for fingerprint calculator
Also working around odd "which line is the Twig code on" issue that suddenly appeared on this PR by moving that all onto one line.
1 parent 4546f53 commit 18fb8a0

File tree

7 files changed

+11
-20
lines changed

7 files changed

+11
-20
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ jobs:
270270
- name: Notify Tests
271271
working-directory: src/Notify
272272
run: php vendor/bin/simple-phpunit
273-
273+
274274
- name: Translator Dependencies
275275
uses: ramsey/composer-install@v2
276276
with:

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
194194

195195
$container->register('ux.live_component.deterministic_id_calculator', DeterministicTwigIdCalculator::class);
196196
$container->register('ux.live_component.fingerprint_calculator', FingerprintCalculator::class)
197-
->setArguments([new Reference('serializer'), '%kernel.secret%']);
197+
->setArguments(['%kernel.secret%']);
198198

199199
$container->setAlias(ComponentValidatorInterface::class, ComponentValidator::class);
200200

src/LiveComponent/src/LiveComponentHydrator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
*/
3737
final class LiveComponentHydrator
3838
{
39-
public const LIVE_CONTEXT = 'live-component';
4039
private const ATTRIBUTES_KEY = '@attributes';
4140
private const CHECKSUM_KEY = '@checksum';
4241

src/LiveComponent/src/Twig/DeterministicTwigIdCalculator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private function guessTemplateInfo(): array
102102

103103
// update template name
104104
// START CHANGE
105-
// don't check name poroperty
105+
// don't check name property
106106
// if (null !== $template && null === $this->name) {
107107
if (null !== $template) {
108108
// END CHANGE

src/LiveComponent/src/Util/FingerprintCalculator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace Symfony\UX\LiveComponent\Util;
1515

16-
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17-
use Symfony\UX\LiveComponent\LiveComponentHydrator;
1816
use Symfony\UX\LiveComponent\Metadata\LiveComponentMetadata;
1917

2018
/**
@@ -33,7 +31,6 @@
3331
class FingerprintCalculator
3432
{
3533
public function __construct(
36-
private NormalizerInterface $objectNormalizer,
3734
private string $secret,
3835
) {
3936
}
@@ -46,8 +43,6 @@ public function calculateFingerprint(array $inputProps, LiveComponentMetadata $l
4643
return '';
4744
}
4845

49-
$normalizedData = $this->objectNormalizer->normalize($fingerprintProps, context: [LiveComponentHydrator::LIVE_CONTEXT => true]);
50-
51-
return base64_encode(hash_hmac('sha256', serialize($normalizedData), $this->secret, true));
46+
return base64_encode(hash_hmac('sha256', serialize($fingerprintProps), $this->secret, true));
5247
}
5348
}

src/LiveComponent/tests/Fixtures/templates/components/todo_list_with_keys.html.twig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33

44
<ul>
55
{% for key, item in items %}
6-
{{ component('todo_item', {
7-
text: item.text,
8-
textLength: item.text|length,
9-
key: 'the-key'~key,
10-
}) }}
6+
{{ component('todo_item', { text: item.text, textLength: item.text|length, key: 'the-key'~key }) }}
117
{% endfor %}
128
</ul>
139
</div>

src/LiveComponent/tests/Functional/EventListener/InterceptChildComponentRenderSubscriberTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ public function testItUsesKeysToRenderChildrenLiveIds(): void
109109
$fingerprints = [];
110110
foreach ($fingerprintValues as $key => $fingerprintValue) {
111111
// creating fingerprints keys to match todo_list_with_keys.html.twig
112-
$fingerprints['live-4172682817-the-key'.$key] = $fingerprintValue;
112+
$fingerprints['live-1745423312-the-key'.$key] = $fingerprintValue;
113113
}
114-
$fingerprints['live-4172682817-the-key1'] = 'wrong fingerprint';
114+
$fingerprints['live-1745423312-the-key1'] = 'wrong fingerprint';
115115

116116
$urlSimple = $this->doBuildUrlForComponent('todo_list_with_keys', []);
117117
$urlWithChangedFingerprints = $this->doBuildUrlForComponent('todo_list_with_keys', $fingerprints);
@@ -120,14 +120,15 @@ public function testItUsesKeysToRenderChildrenLiveIds(): void
120120
->visit($urlSimple)
121121
->assertSuccessful()
122122
->assertHtml()
123+
->dump()
123124
->assertElementCount('ul li', 3)
124125
// check for the live-id we expect based on the key
125-
->assertContains('data-live-id="live-4172682817-the-key0"')
126+
->assertContains('data-live-id="live-1745423312-the-key0"')
126127
->assertNotContains('key="the-key0"')
127128
->visit($urlWithChangedFingerprints)
128-
->assertContains('<li data-live-id="live-4172682817-the-key0"></li>')
129+
->assertContains('<li data-live-id="live-1745423312-the-key0"></li>')
129130
// this one is changed, so it renders a full element
130-
->assertContains('<li data-live-name-value="todo_item" data-live-id="live-4172682817-the-key1"')
131+
->assertContains('<li data-live-name-value="todo_item" data-live-id="live-1745423312-the-key1"')
131132
;
132133
}
133134

0 commit comments

Comments
 (0)