Conversation
|
Hey @erwinmombay! These files were changed: |
|
I'm currently re-using the I couldn't decide one way or the other. It seems like |
| 'getProp', | ||
| 'mutateElement', | ||
| 'mutateProps', | ||
| 'registerAction', |
There was a problem hiding this comment.
nit: do we want registerAction? my impression is that we'd only ever want the api interface
There was a problem hiding this comment.
Minimally, yes, we only need to proxy api() object. But I think Justin is trying to say here that the PreactBaseElement still has to serve both worlds so moth sets of APIs are still required.
dvoytenko
left a comment
There was a problem hiding this comment.
This looks like taking a clear shape! I'd still like a however-minimal design doc. Some important items:
- Boilerplate needs to change for Bento. Not clear how to do it "cleanly" yet. But we need to call it out in the doc as an open problem.
- There are some very clear and "cheap" actions we can take now and split the work that would make this whole thing a lot easier. Namely, we just need to devirtualize CustomElement and BaseElement APIs. Anything from
applyFillContenttogetRealChildrencan and should just become staticexport functionsomewhere. - Some of the critical decisions we'd have to make are thing like: do we have separate binaries for
amp-carousel-0.1.js?bento? Or just one binary would suffice. This is something that design doc could highlight pretty well, including an estimate of the envelope's binary size. - We need to come up with an "easy" way to proxy
PreactBaseElement.api()on the element.
| 'getProp', | ||
| 'mutateElement', | ||
| 'mutateProps', | ||
| 'registerAction', |
There was a problem hiding this comment.
Minimally, yes, we only need to proxy api() object. But I think Justin is trying to say here that the PreactBaseElement still has to serve both worlds so moth sets of APIs are still required.
| <link rel="canonical" href="amps.html"> | ||
| <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
| <!-- <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> --> | ||
| <style amp-boilerplate> |
There was a problem hiding this comment.
So, this is a good point. We essentially want a different boilerplate ideally. Not sure yet how we can reconcile this with AMP mode. Ideally delta is somewhat small...
There was a problem hiding this comment.
Can you explain this?
In Bento mode wouldn't we not want any boilerplate.
For regular AMP mode, why do the boilerplate requirements change?
Admittedly I don't know much about our boilerplate except that we have visibility:hidden until the page has loaded to prevent FOUC
| } else { | ||
| const container = doc.createElement('i-amphtml-c'); | ||
| this.container_ = container; | ||
| this.applyFillContent(container); |
There was a problem hiding this comment.
Ok. This is a good track item: we really want to hollow out CustomEleemnt and BaseElement APIs. Sort of - everything that can become a static util - we should just make a static util, e.g. in a dom.js or a similar package.
| * @param {function():undefined} cb | ||
| */ | ||
| mutateElement(cb) { | ||
| Promise.resolve().then(cb); |
There was a problem hiding this comment.
This would probably be best to be done via setTimeout(0). That way the ordering of a mutation is still predictable. Vs a microtask ordering is completely random from the caller's point of view. Also, I think we might have more problems from overloading microtasks then tasks.
There was a problem hiding this comment.
just to confirm: while this fn is necessary while we still need useResourcesNotify, ideally we can rm this fn right?
| const payload = extensionPayload(name); | ||
|
|
||
| return ( | ||
| `(function(p){self.AMP?self.AMP.push(p):` + |
There was a problem hiding this comment.
This is a bit tough for me to read. Is there any way for us to write this with standard-looking JS and then minify/turn into a string separately? Or at a minimum include a comment explaining what happens here.
My take:
- Check if its a page with Runtime present (via v0 presence in the head or if self.AMP is already initialized)
2a. If yes, then add this extension to the AMP init array (or create it)
2b. Otherwise, define the CE immediately
Did I get that right?
| <link rel="canonical" href="amps.html"> | ||
| <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
| <!-- <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> --> | ||
| <style amp-boilerplate> |
There was a problem hiding this comment.
Can you explain this?
In Bento mode wouldn't we not want any boilerplate.
For regular AMP mode, why do the boilerplate requirements change?
Admittedly I don't know much about our boilerplate except that we have visibility:hidden until the page has loaded to prevent FOUC
| super(); | ||
|
|
||
| /** @const {!CeBaseElement} */ | ||
| this.implementation = new BaseElement(this); |
There was a problem hiding this comment.
Should the BE implementation be initialized in the CE ctor, or in connectedCallback? I know you had intended on deferring construction to connectedCallback for AMP mode so that we can ensure the document and services are available, but updating all the unit tests was a gargantuan task
| * @param {function():undefined} cb | ||
| */ | ||
| mutateElement(cb) { | ||
| Promise.resolve().then(cb); |
There was a problem hiding this comment.
just to confirm: while this fn is necessary while we still need useResourcesNotify, ideally we can rm this fn right?
| if (typeof AMP !== 'undefined' && AMP.BaseElement) { | ||
| BaseElement = AMP.BaseElement; | ||
| } else { | ||
| class CeBaseElement { |
There was a problem hiding this comment.
Did you experiment with trying to only have a CustomElement definition instead of a separate BaseElement as well? Do you think Bento components rely on helpers and utilities that would break without continuing the split
|
Batch closing Bento PRs. |
This is a WIP PR to add Bento mode (HTML page not managed by v0 Runtime) support to our Bento components. This requires several pieces:
BaseElementimplementationCustomElementimplementation to wrap theBaseElement