Skip to content

amp-bind: Cycles with amp-state's [src] binding  #8948

@dreamofabear

Description

@dreamofabear

Issue

amp-state's ability to trigger setState from a [src] binding causes a possible cycle:

<amp-state id="myState" [src]="'/myEndpoint?foo=' + myState.foo"></amp-state>

If the /myEndpoint?foo= XHR returns {foo: <random number>}, then the XHRs will trigger incessantly: [src] mutation -> setState -> [src] mutation

Should only be an issue with amp-state since it's essential behavior is updating the state. Hitherto, no element calls setState via a bind mutation.

A few possible solutions

  1. Remove [src] binding for amp-state, instead use forms as described in amp-bind: Support e-commerce XHR use case #8648 (comment).
  2. Change amp-state[src] XHR to only update state and not apply bindings, instead force use of a separate action myAmpState.refresh.
  3. State change due to amp-state[src] will ignore mutations to amp-state elements.

Props to @kmh287 for pointing this out!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions