-
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> forbids mutations in a way that's confusing #26524
Comments
Trying with layout="responsive", dimensions not set: fetch() fails on load. fetch() works >5 seconds on user event. |
Ah, so the actual two cases aren't Your discovery regarding initial mutations always being allowed is being addressed by #26401. The only thing I'm left puzzled by is why |
Just used the AMP Playground to test this out. If you either have the interval not perform mutation (e.g. console.log) OR give it a fixed layout, then setInterval won't cause the worker to be terminated. |
Yep, you're right - the cases do collapse: layout=="container": immediate mutation allowed. setInterval() disallowed on load. setInterval() works for 5 seconds after user event. layout!="container", dimensions set: immediate mutation allowed. setInterval() works forever on load or on user event. layout!="container", dimensions not set: immediate mutation allowed. setInterval() fails on load. setInterval() works for 5 seconds on user event. This is close to what's documented, but not quite the same. And I'm not sure whether it's the behavior we desire.... |
Oh, and one more: layout!="container", dimensions not set: fetch() fails on load. fetch() works >5 seconds (probably forever) on user event. So, the question is, why do we allow some mutations forever, but others for 5 seconds? |
I think explaining some of the rationale behind how/why the cases collapse can help (and why container is important here).
With that rationale in mind, here are cases that collapse:
There are two things you called out that are inconsistent and we should get to the bottom of:
|
About #2 above: sorry, I began to use shorthand and was unclear! When I talk about Notice however that the behavior's always the same when layout=="container", whether dimensions are set there or not. So, collapsing the cases: layout=="container", or layout!="container" && dimensions not set: immediate mutation allowed. setInterval() disallowed on load. setInterval() works for 5 seconds after user event. layout!="container" && dimensions set: immediate mutation allowed. setInterval() works forever on load or on user event. The first case makes sense to me, if we document it clearly: if the element doesn't have fixed dimensions, we allow limited changes after a user event. Or on load, which, as you say, we don't actually want to do. The second case also makes sense: if dimensions are fixed, do whatever you want. Although of course the developer could make all sorts of crazy things happen in a quite large space if they wanted to.
|
@morsssss: I think you've correctly collapsed the cases. One more detail about what we intend to allow on load is that I think we want to allow for all non-visible mutations. Things like adding event listeners, and Is there anything else we should get to the bottom of before closing this issue? |
Hi all, |
Ok, I did another thorough test here. This time, I put my results in a table so that they would make maximum sense. I don't have the patience to convert this to MD, so here's a lovely screenshot: Arranging the results in the proper order makes the current state of things clear. We have a set of restrictions in place for these cases:
And no restrictions whatsoever in this case:
I think this is simple enough to keep the current behavior and document it, even though it's a littttle confusing. And I know we do want to change the onload behavior. On the other hand, what @AndrewKGuan points out is concerning. Andrew, can you share your code? If so this should become a different issue. |
Amendment: as we've been discussing, we don't actually allow changes forever after a |
Ok, @samouri , two more things...
|
also, @AndrewKGuan , you're right - state can't be set if layout=='container', whether dimensions are set or not. But if layout != 'container', it's allowed. Which brings up again the question I saw in #26401 : should |
For (1), it is that we simply can't figure out the desired height otherwise. Theres no way of directly seeing what the user specified in CSS for the HTML element. For (2), thats because Lines 140 to 155 in 3199056
|
Well, this could be a problem, but I've never heard anyone complain about it. We'll see if it becomes a problem.
|
I'm going to go ahead and change the documentation to reflect what we've determined here. So, it's not I can close this issue and make a new one for the |
Preamble
amp.dev says:
The rules for mutations are as follows:
I didn't find this behavior to be consistent, so I finally did some testing! The results lead me to believe that we may not be applying these rules consistently. Either we should change the documentation or the way we apply the rules.
(I haven't tested
fetch()
yet. But I did usesetTimeout()
andsetInterval(func, 200)
to see how long mutations were permitted.)Tests
I thought these would be the two possible cases: layout == "fixed" or layout != "fixed". But layout=="container" was a bit different:
See also #26511
/cc @samouri
The text was updated successfully, but these errors were encountered: