-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(repeater): bubble afterStateUpdated to parents #16093
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
base: 3.x
Are you sure you want to change the base?
fix(repeater): bubble afterStateUpdated to parents #16093
Conversation
When you mention parent components, can you provide an example of some code that is currently broken? I'm not even sure that running the hook on parents is desired behaviour but I would like to hear what you are using this for first? |
For example, in our case we have a Example: Section::make()
->schema([
TextInput::make('heading'),
Repeater::make('blocks')
->schema([
TextInput::make('image'),
]),
])
->afterStateUpdated(fn () => $this->updatePreview())
->live(), Normally, if a user edits the Problem: If a user adds, deletes, reorders or does any of the repeater actions inside the This is why we made the change to bubble |
Does the section have a |
Only thing relevant it has is (Sorry, I forgot to include that in the example.) |
Honestly that is super weird behaviour, I never knew it did that. So I will need to look into the underlying cause and decide whether or not that is desired behaviour. Sorry, that will result in a delay to this PR. |
No worries, I’ll be here to help if I can. |
Description
This PR addresses an issue where
afterStateUpdated
callbacks on parent components were not being triggered after running repeater-related actions such as add, delete, reorder, etc.In these cases, the component would call
afterStateUpdated
on itself at the end of the action, but unlike normal state updates, the update did not bubble up to its parent components. This meant any logic relying onafterStateUpdated
at the parent level would silently fail to run.To fix this, a new helper was introduced that first checks if the component is live, and then recursively walks up the component tree, calling
afterStateUpdated
on each parent. This mirrors the behavior of actual state updates, ensuring that all necessary callbacks are triggered.This approach has worked well in our testing and reflects the expected behavior of how state updates should propagate. Let me know if there’s a more appropriate way to handle this logic, or if there are any edge cases we might’ve missed.
Visual changes
No visual changes.
Functional changes
composer cs
command.