amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-script: binding can cause real DOM and virtual DOM to get out of sync

Open morsssss opened this issue 5 years ago • 3 comments

I'm not sure there's a great solution to this one. I'm just reporting it as an issue in case someone sees a solution... and otherwise I'm just documenting the behavior.

If another process modifies an <amp-script>'s children, that change won't propagate to the virtual DOM - and the user's JavaScript will see stale data.

Here's one way in which this can happen:

<amp-script layout="container" script="myscript">
  <p [text]="myText">Will I change?</p>
</amp-script>
<button on="tap:AMP.setState({myText: 'I changed'})">Change this and amp-script won't know</button>

morsssss avatar Aug 20 '20 22:08 morsssss

Solution: amp-bind should not be modifying elements within an amp-script :).

samouri avatar Feb 19 '21 04:02 samouri

This is true! I did indeed document it :) Don't suppose it's a case where we'd want amp-bind to throw a warning or something, if amp-bind even has the ability to search its ancestor elements for an amp-script...

morsssss avatar Feb 19 '21 15:02 morsssss

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 19 '25 08:07 stale[bot]