Skip to content

Conversation

@weaverryan
Copy link
Member

Q A
Bug fix? no
New feature? yes
Issues Fix #1212
License MIT

Hi!

If you use the model:set hook, and a prop changes on the server during a re-render, when the Ajax call finishes, model:set will now be called. Details:

A) The code was a bit complex, but for writable sub-properties (#[LiveProp(writable: 'firstName, 'lastName'] above a user property), model:set is called for each sub-key that changes - e.g. user.firstName and user.lastName. That is consistent with the behavior if those were changed by the user (e.g. by typing into a user.firstName input).

B) If the user changes a prop during the Ajax request (e.g. they type into user.firstName), then model:set will not be triggered for this one model. That's because the "frontend value" takes precedence over any server updates (this has always been the case). And so, the end result is that, even if the server changed user.firstName, after the Ajax call finishes, the actual value of that prop on the frontend will be whatever the user changed it to during the re-render.

Cheers!

}

private function verifyChecksum(array $identifierPops, string $error = 'Invalid checksum sent when updating the live component.'): void
private function verifyChecksum(array $identifierProps, string $error = 'Invalid checksum sent when updating the live component.'): void
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated - just identified this typo.

@weaverryan weaverryan force-pushed the live-model-set-from-server branch from d82ee7a to fe3e16a Compare November 6, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant