Any update on amp-state will trigger global re-render
Whenever there's an update to amp-state, all amp-bound elements on the page will get re-evaluated and re-rendered, even when the elements are not bound to the updated amp-state variables.
One simple example here: http://testmip.herokuapp.com/triplelinkeddropdown.html
The second drop down does not retain selected value because it's been re-rendered after a setState triggered by itself, and the variable being set is not the one bound to the drop down.
I have some other more complicated examples (not yet available publicly) that also exhibit the same behavior.
A work-around for this behavior is to store and set the selected state via amp-bind. This makes things unnecessarily complicated though.
We actually currently do this but only check recursive equality of arrays/objects to a depth of 3 (which falls just short of your use case). I think we can bump it up safely.
Hi William, would this change help prevent any amp-bound template-generated elements from overwritten? For example, a form with a combination of multiple inputs textboxes and a group of radio buttons (observing tap event) dynamically generated from amp-state json, will tapping on the radio buttons wipe out texts a user entered in those textboxes?
Yes, but only if the output of the template render is identical. We haven't implemented diffing of rendered templates yet, e.g. only append new elements instead of re-rendering everything.
Would that be useful for your use case?
Hello,
Has this regressed. If I look at the amp.dev playground example,
https://playground.amp.dev/?url=https://preview.amp.dev/documentation/examples/components/amp-bind
Clicking on any of the buttons causes all the state across the page to be re-evaluated. Should this not be scoped to a given action alone?
@shishirm This was always the case. You can use default values in expressions to avoid this behavior e.g. [text]="foo || 'default text'".