-
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-story-embed] Adds messaging, implements build/layoutcallbacks #26305
Conversation
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.
As commented below, I think some of this PR is taking us further from the end goal.
What we want is a piece of code that loads or prerenders a story, that we can call again and again as the user progresses through the feed of story.
This PR moves away from this and loads all the stories at the same time, which is a piece of code we'll never need in the final library.
Decided to move the loading one iframe + prerendering the next ones logic to another PR, to keep this one small and focused. PTAL. |
ab0e69a
to
28b71cc
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.
Can you add some basic unit tests? I know we want to ship this asap but I believe it'll save us time :)
b024467
to
578c398
Compare
PTAL @gmajoulet also need owners approval from @jridgewell / @choumx for |
c4b1d85
to
f6f7c6e
Compare
src/amp-story-embed.js
Outdated
}); | ||
|
||
let inputUrl = addParamsToUrl(href, params); | ||
inputUrl = inputUrl.replace('amp_js_v=0.1', 'amp_js_v=0.1#'); |
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.
Isn't this going to leave an extra &
after the #
?
Also, this won't work as addParamsToUrl
seems to be adding the query parameter before the hash
. You'd break the canonical URL by having the original hash at the very end of the URL.
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.
Good catch! I am now extracting the original fragment param first before prepending it again after adding the new parameters.
f6f7c6e
to
bb6eb39
Compare
PTAL @gmajoulet |
Friendly ping |
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.
Looking good :))
src/amp-story-embed-manager.js
Outdated
this.win_ = win; | ||
|
||
/** @private {?AmpStoryEmbed} */ | ||
this.currentEmbed_ = null; |
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.
Nit: we should not write code that's only used for unit testing purposes (this and the getEmbed()
method). Do you have another way of writing your test that wouldn't need this piece of code?
getEmbed
returns you a pretty arbitrary embed (the last one), and currentEmbed
doesn't make sense if there are two embeds side to side in the page
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.
Done.
src/amp-story-embed-manager.js
Outdated
return; | ||
} | ||
|
||
this.layoutFallback_(embedImpl); |
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.
Might be easier to read with an early return after this one line?
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.
Done.
this.messagingFor_ = {}; | ||
|
||
/** @private {!Array<!Element>} */ | ||
this.iframes_ = []; |
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.
A few thoughts for another PR: I'm almost wondering if we should just store the story URLs instead of the iframes, so you can rotate through 3 or 5 iframe elements. Storing the actual iframes will make it harder/impossible to re-use the iframe elements.
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.
Yep, this was one of the approaches I was thinking for my next PRs when enabling multiple stories and I agree we should rotate through a fixed amount of iframes.
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.
PTAL
src/amp-story-embed-manager.js
Outdated
this.win_ = win; | ||
|
||
/** @private {?AmpStoryEmbed} */ | ||
this.currentEmbed_ = null; |
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.
Done.
src/amp-story-embed-manager.js
Outdated
return; | ||
} | ||
|
||
this.layoutFallback_(embedImpl); |
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.
Done.
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.
Great! 👍
cdd32c6
to
b466435
Compare
/to @jridgewell @choumx for OWNERS approval |
PTAL @jridgewell @choumx |
Ping @jridgewell |
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.
One last question, but LGTM otherwise.
Thanks all, merging! |
Partial for #24539
This PR adds:
layoutCallback()
with a fallback that uses a scroll listener.Things I'm not sure about:
@ampproject/viewer-messaging
), yarn.lock has been updated, but I don't know if that should be in my local gitignore or if it should actually be checked in.Issue tracker #26308