Skip to content
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

🏗Multi-doc manager refactor #25629

Merged
merged 11 commits into from
Dec 10, 2019
Merged

Conversation

wassgha
Copy link
Contributor

@wassgha wassgha commented Nov 17, 2019

Closes #25630 , partial for #25500

Changes

  • Separates MultidocManager from runtime.js
  • Exports the dependencies that MultidocManager requires and injects them through the global.AMP object (only for the v0.js and shadow-v0 bundles, excludes inabox/amp4ads and video-iframe-integration. Biggest gain from this is a smaller amp-next-page bundle size with no significant runtime size increase.

Bundle size results

dist/amp4ads-v0.js: Δ -0.08KB
dist/shadow-v0.js: Δ +0.02KB
dist/v0.js: Δ -0.03KB
dist/v0/amp-next-page-0.1.js: Δ -38.44KB

@wassgha wassgha force-pushed the dynamic-shadow-mode branch 2 times, most recently from b264cdb to b505c10 Compare November 17, 2019 20:29
@amp-bundle-size amp-bundle-size bot requested a review from jridgewell November 17, 2019 20:37
@wassgha wassgha removed the request for review from jridgewell November 18, 2019 03:44
@amp-bundle-size amp-bundle-size bot requested a review from jridgewell November 18, 2019 03:57
@wassgha wassgha removed the request for review from jridgewell November 21, 2019 06:17
@wassgha wassgha changed the title ✨Implements dynamic adoption of shadow mode 🏗Multi-doc manager refactor Nov 21, 2019
@wassgha wassgha force-pushed the dynamic-shadow-mode branch from 5597732 to 5da1154 Compare November 21, 2019 19:14
@wassgha wassgha requested review from jridgewell and removed request for dreamofabear November 21, 2019 20:54
Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works, awesome! Can you post the filesize diffs for v0.js and amp-next-page.js (compiled)?

src/runtime.js Outdated Show resolved Hide resolved
/**
* A manager for documents in the multi-doc environment.
*/
export class MultidocManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

dev().fine(TAG, 'Attach to shadow root:', shadowRoot, ampdoc);

// Install runtime CSS.
installStylesForDoc(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing a diff, these two lines seem to be the only changes? I'm astounded that this was all that's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! I essentially did a diff of multidoc-manager dependency tree and runtime's dependency tree to see what multidoc-manager needs that's not provided by runtime. I'll do more testing to make sure this doesn't break anything, otherwise I'll just exclude the inabox runtime from this change and we should be good to go.

@wassgha wassgha force-pushed the dynamic-shadow-mode branch from deb0c1d to c9e9b73 Compare December 4, 2019 19:12
@wassgha wassgha force-pushed the dynamic-shadow-mode branch from c9e9b73 to 4266acf Compare December 5, 2019 21:24
@wassgha wassgha marked this pull request as ready for review December 5, 2019 21:34
@wassgha wassgha requested a review from jridgewell December 5, 2019 21:34
@wassgha
Copy link
Contributor Author

wassgha commented Dec 5, 2019

Split the adopt method in runtime into adopt and adoptWithMultidocDeps so that amp4ads doesn't need to include these MultidocManager-specific imports. Not sure how to thoroughly test this for any race conditions, would love some input @jridgewell

/**
* Applies the runtime to a given global scope for shadow mode.
* @param {!Window} global Global scope to adopt.
* @return {!Promise}
*/
export function adoptShadowMode(global) {
return adoptShared(global, (global, extensions) => {
// shadow mode already adopted
if (global.AMP.attachShadowDoc) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm not sure I understand, it's set under it on line 426

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, that's not part of Github's diff display.

Copy link
Contributor

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

/**
* Applies the runtime to a given global scope for shadow mode.
* @param {!Window} global Global scope to adopt.
* @return {!Promise}
*/
export function adoptShadowMode(global) {
return adoptShared(global, (global, extensions) => {
// shadow mode already adopted
if (global.AMP.attachShadowDoc) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, that's not part of Github's diff display.

@wassgha wassgha merged commit afb060c into ampproject:master Dec 10, 2019
@wassgha wassgha deleted the dynamic-shadow-mode branch December 10, 2019 06:37
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
* Separates multidoc-manager from the runtime

* Export installAmpdocServices

* Implements dynamic adoption of shadow mode

* Type check

* Fix type checking

* Revert dynamic adoption

* Export css dependency from multidoc-manager

* Removed dynamic asdoption of shadow mode

* Excludes inabox and video-iframe-integration from requiring Multidoc dependencies

* Type check fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic adoption of shadow mode
3 participants