Skip to content

Conversation

@weaverryan
Copy link
Owner

@weaverryan weaverryan commented Oct 14, 2022

  1. BACKEND: pass a "fingerprint" value to Stimulus (fingerprint is a checksum of the values passed IN when creating a component)

symfony#500

The reason for this is explained by the same flow:

A) Component parent renders & all children are given a "fingerprint" (this PR!) that is a checksum of the "input" passed to create that child
B) On parent re-render, an array containing [{ id: 'the-child-id', fingerprint: 'its fingerprint'}, ... ] is sent along with the parent component data.
C) We will (still a TODO - 6 on the linked PR) use that info to figure out if the "fingerprint" of any specific children has changed (i.e. we calculate the deterministic id of a child component, find its fingerprint using that id from the data above, and compare).

@weaverryan weaverryan changed the base branch from 2.x to component-object October 14, 2022 00:40
@weaverryan weaverryan force-pushed the component-object-fingerprint-value branch from 36f146c to e49933a Compare October 14, 2022 00:40
@weaverryan weaverryan changed the title cd ..Component object fingerprint value Component object fingerprint value Oct 14, 2022
@weaverryan weaverryan changed the title Component object fingerprint value cd ..Component object fingerprint value Oct 14, 2022
@weaverryan weaverryan changed the title cd ..Component object fingerprint value Component object fingerprint value Oct 14, 2022
Copy link

@kbond kbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor things.


public function calculateFingerprint(array $data): string
{
return base64_encode(hash_hmac('sha256', serialize($data), $this->secret, true));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all internal so we can change later but maybe we should create a ChecksumCalculator object that's used for calculating the checksum and the fingerprint?

In a future PR, will you need to verify the fingerprint?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to save for later, but you're right.

Related, it's odd to have to pass the $secret into DehydratedComponent. Probably there should be a DehydratedComponentFactory and some of the DehydratedComponent logic (i.e. public static function createFromCombinedData and the checksum creation) should be moved there.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a new ChecksumCalculator would contain the secret - once we have this service, it will probably require some refactoring of DehydratedComponent.

@weaverryan
Copy link
Owner Author

Merged in now - thanks for the review :)

@weaverryan weaverryan closed this Oct 14, 2022
@weaverryan weaverryan deleted the component-object-fingerprint-value branch October 17, 2022 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants