-
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
Deferred build API and builder #32568
Deferred build API and builder #32568
Conversation
f17e519
to
6c385ba
Compare
feae689
to
5f7db6c
Compare
5f7db6c
to
06ef0f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really impressive! As much as I'm daunted by the scope of the change and its implication, it is 100% the right direction (deferring constructor, build, and layout). I haven't had a chance to review the test changes yet.
old (v1)
AMP Component authors write a class that extends BaseElement. It has two overridable functions: buildCallback and layoutCallback, both called by the API. buildCallback is essentially always called ASAP whereas layoutCallback is determined by a relatively complex set of rules around viewport intersection, displayability (size > 0), and relative priority to other components in the middle of being processed.
new (v2)
AMP Components author write a class that extends BaseElement. Only overridable fn of note is buildCallback. Instead of ASAP, this gets called by the Runtime when close to viewport. Most auxiliary callbacks are deprecated. Priority only determines whether setTimeout or setIdleCallback are used.
06ef0f7
to
9f16640
Compare
@samouri responded to all comments. PTAL. |
* @param {!AmpElement} target | ||
*/ | ||
scheduleAsap(target) { | ||
this.targets_.set(target, {asap: true, isIntersecting: false}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming targets
should already contain the target element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They likely do - this just overrides it for new urgency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an assertion? I'm worried we'll hit a double build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double-builds are definitely not possible. The CustomElement itself prevents them and there are a few tests on that subject. So it's ok even if somehow the build is scheduled twice. However, in this particular case it's very much expected that this call will override the existing information. It basically says: "don't worry about what you already know, just go ahead and build". Does it make sense?
This pull request introduces 2 alerts when merging cc00b43 into fac0f5f - view on LGTM.com new alerts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one potentially blocking comment regarding READY_SCAN_SIGNAL
. The rest of my comments were either questions or nits.
@samouri @jridgewell I've responded to all comments. PTAL. |
* @param {!AmpElement} target | ||
*/ | ||
scheduleAsap(target) { | ||
this.targets_.set(target, {asap: true, isIntersecting: false}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add an assertion? I'm worried we'll hit a double build.
ec325fb
to
1bc63ef
Compare
Hey @gmajoulet, @newmuis, @Enriqe! These files were changed:
|
Since we confirmed the API I switched a couple of relevant dependents to the new API. Where immediate build is needed, it now calls |
d92b1f5
to
01a8e17
Compare
01a8e17
to
49143c0
Compare
@dvoytenko I'm seeing several instances of a failing test since this PR was merged. Related? Rendering of amp-img
✗ should respect media queries
AssertionError: expected null to exist
at _callee5$ (/tmp/test/integration/test-amp-img.js:94:7)
at tryCatch (/tmp/node_modules/fetch-mock/es5/client-bundle.js:1291:52)
at Generator.invoke [as _invoke] (/tmp/node_modules/fetch-mock/es5/client-bundle.js:1521:34)
at Generator.next (/tmp/node_modules/fetch-mock/es5/client-bundle.js:1346:33)
at asyncGeneratorStep (/tmp/e585455f262f4c5569ed473042a40762.browserify.js:148234:103)
at _next (/tmp/e585455f262f4c5569ed473042a40762.browserify.js:148236:194) |
From the perspective of a |
I'd say it's more than that. It includes:
And the things you mentioned:
|
The reason I ask, is because I'm suspicious of the last two you said. Should a loading indicator be controlled by Runtime, or in the ideal world would it too be moved to the individual components |
It's controlled by each individual |
By individual extensions of BaseElement. I.e. should amp-instagram control its own loading indicator. |
It does control it now individually. It's just provided on the But TBH I definitely see us moving more of the |
Partial for #31915.
TODO:
Support amp-video experiment for V2