Should Bento component implementations be compatible with Amp Services? #5
Replies: 5 comments 5 replies
-
Approach #1: AbstractionMany existing Bento components use optional props to keep Amp-specific features separate from the Bento implementation. For example, with AdvantagesMany components have already been ported this way. Sometimes the abstraction is a useful public API (like the custom LimitationsThis approach only works fine for small-scale abstractions. A custom However, some components rely heavily on multiple Services, and it would be very difficult to attempt to abstract away all service calls. For example, Additionally, some Bento components have already been ported WITHOUT certain Service-powered features. For example, the Bento version of |
Beta Was this translation helpful? Give feedback.
-
Approach #2: Service injectionFor components that rely heavily on Services, we could start by creating “standalone” versions of these services (with similar APIs). Then, the Bento component would use these standalone services, unless the AMP-wrapper provided/injected a different implementation. AdvantagesThis would allow Bento components to be ported more easily, since the service calls would remain about the same. It would allow Bento components to take advantage of features that only exist in AMP documents (eg. LimitationsImplementing the standalone versions might be ugly; there might be a lot of methods that are not applicable (therefore are just noops), or could be needlessly async (so the API signature matches). It might be challenging to ensure that the “standalone” services can be tree-shaken (dead code removal). Examplefunction BentoComponent({ AmpServices }) {
const xhr = AmpServices?.get('xhr') || xhrStandalone;
const doc = AmpServices?.get('doc') || docStandalone;
const url = AmpServices?.get('url') || urlStandalone;
// Example usage:
const result = getAppInfo({ xhr, doc, url });
return <>{result}</>;
} |
Beta Was this translation helpful? Give feedback.
-
I was only able to make the second half of the design review. Can anyone summarize why we ended up leaning towards Option 2 instead of Option 1 (especially given Alan's comment). I do see how (2) would allow us to think less and move faster, but I'm worried about increasing the complexity within Bento to serve AMP, as well as long-term performance due to worse DCE. If end up choosing (2), then I think we should also rename |
Beta Was this translation helpful? Give feedback.
-
Approach #3: Document-level scoping of utilsAs discussed in approach 1 above, there are "AMP-only" services (not needed by Bento), and there are "utility" services (useful to Bento). Instead of injecting full AMP services into Bento components (approach 2) to solve this issue, we can instead inject just the Advantages
Limitations
Example:
|
Beta Was this translation helpful? Give feedback.
-
FWIW: Approach #3 was implemented here: ampproject/amphtml#37465 However, after further discussions, we have dropped support for AMP mode within Bento components. Therefore, this issue is no longer relevant, and the PR above was abandoned. |
Beta Was this translation helpful? Give feedback.
-
Many Amp components rely on Services for many of their features. These services can be purely utility (eg.
platform
), while some maintain state or cache (eg.xhr
), and some have multiple implementations to work across document boundaries (eg.viewer
).To convert these Amp components to Bento, we need to decide how these features will be ported.
And if Bento components are intended to be used in Amp documents, then it’s especially important to determine how Bento components can utilize Amp-specific logic when necessary (like xhr batching, preconnects, templates, amp-cache awareness, etc) so they can be feature-complete replacements.
Beta Was this translation helpful? Give feedback.
All reactions