ux icon indicating copy to clipboard operation
ux copied to clipboard

[Live] Fixing lost behavior of handling element with an action and a model on it

Open weaverryan opened this issue 1 year ago • 1 comments

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

UPDATE

I think this fix is not needed at all - I think #1557 happened just due to the "gotcha" listed below. If you fix that, things DO work... and we even have a test for this :). I've reverted my fix... this is now just a docs PR.


This is old behavior that we once had, but got lost in a reshuffle of code a long time ago. It's an edge case. Imagine:

<input data-model="count" data-action="live#action" data-live-action-param="doSomething">

This element is both bound to a count model and should trigger an action. Due to how the events are registered, here is the natural order:

  1. The action() is triggered
  2. THEN the model is updated

The result is that the doSomething LiveAction is triggered... but without the updated count value. Our fix is to detect this situation and add a slightly delay (waiting for the potential model update) before triggering the action.

There is one gotcha that will need to be documented: if you (1) trigger the model update on change but trigger the action on input, then the action fires quite a bit before the model is updated on change. This is a misconfiguration, but easy to do with the form system, since change is the default, but any custom data-action on an input will default to the input event.

TODO

  • [x] Add a spot in the docs to describe this & the gotcha
  • [ ] ~~Add tests~~

weaverryan avatar Mar 01 '24 19:03 weaverryan

https://github.com/symfony/ux/issues/1648

smnandre avatar Mar 24 '24 22:03 smnandre