-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
amp-script: Treat AMP.setState as "high trust" from user gesture #24862
Comments
This is because |
Addendum: If the |
But setting state inherently can affect elements outside the <!-- ... -->
<body class="mode-light" [class]="'mode-' + mode">
<amp-state id="mode"><script type="application/json">"light"</script></amp-state>
<!-- ... --> That seems very useful but it also seems somewhat perilous as setting page state could allow endless content shifting opportunities. |
Yea, the idea is to only mutate the DOM of the |
@choumx : Does that mean amp-bind will mutate once fulfill requests fixed-layout and < 300px height ? <amp-script width="300" height="100" script="local-script">
<p [text]="status.cat">cat name</p>
</amp-script>
<script type="text/plain" target="amp-script" id="local-script">
...
AMP.setState({
status:{
cat: 'shadow'
}
});
</script> But above case doesn't mutate. |
Right, this issue is tracking support for that. It still needs to be implemented. |
It might be worth clarifying this in the docs. Right now they say:
Was wondering why my code manipulating state for elements outside of amp-script wasn't working! |
@choumx, is @alastaircoote's suggestion accurate, that the docs are incorrect? |
Yes, the documentation is misleading. I can quickly fix the problematic sentence. |
I see. Out of curiosity, what's to stop someone from wrapping most of the document in a single amp-script so that all of the relevant components will be updated on setState? |
As far as Ignoring |
Thanks for the info, I almost understand. Could you clarify which of #p1 and #p2 in the user-gesture-based example below will display "Shadow" once this fix is implemented?
|
Both. The more subtle case is:
Then: allow DOM mutation of only |
Got it. The documentation is probably clear enough as-is then, I got tripped up by some of the earlier discussion in the thread. Currently using setState in amp-script anyway ( |
This supplemental semantic has yet to be implemented, though we could track that separately: #24862 (comment) |
Closed by #26046 |
With the following script handler:
Error case here.
amp-bind
updates propagate into the list (with state added per script), butamp-script
changing the state won't cause the list to re-render.The text was updated successfully, but these errors were encountered: