Skip to content

bootCmp - #3661

Merged
oliverlloyd merged 16 commits into
mainfrom
oliver/remove-cmp-from-app
Dec 9, 2021
Merged

bootCmp#3661
oliverlloyd merged 16 commits into
mainfrom
oliver/remove-cmp-from-app

Conversation

@oliverlloyd

Copy link
Copy Markdown
Contributor

What does this change?

This PR moves the initialisation of cmp out of App.tsx and into it's own boot script.

Along with moving the initialisation, I also moved down some code from App.tsx that got the consentState and passed it down to the YouTubeBlockComponent. In doing this, I made it a dynamic import.

Why?

This is part of a wider refactor to remove logic from App.tsx

Things still under consideration

  • Should we use a dynamic import in YouTubeBlockComponent
  • Can we load the bootCmp script later, as a lower priority script tag?

@oliverlloyd
oliverlloyd requested a review from shtukas November 18, 2021 15:45
@oliverlloyd
oliverlloyd requested review from a team, OllysCoding, tjmw and tomrf1 November 18, 2021 15:45
Comment thread dotcom-rendering/src/web/browser/bootCmp/init.ts
Comment thread dotcom-rendering/src/web/components/elements/YoutubeBlockComponent.tsx Outdated
…nent.tsx

Co-authored-by: Max Duval <max.duval@theguardian.com>
@github-actions

github-actions Bot commented Nov 18, 2021 •

Copy link
Copy Markdown

Size Change: -405 B (0%)

Total Size: 3.13 MB

Filename Size Change
dotcom-rendering/dist/elements-CalloutBlockComponent.legacy.js 4.46 kB +1 B (0%)
dotcom-rendering/dist/elements-InteractiveBlockComponent.legacy.js 3.1 kB +4 B (0%)
dotcom-rendering/dist/elements-InteractiveContentsBlockComponent.legacy.js 1.95 kB +1 B (0%)
dotcom-rendering/dist/elements-YoutubeBlockComponent.js 2.57 kB +155 B (+6%) 🔍
dotcom-rendering/dist/elements-YoutubeBlockComponent.legacy.js 2.7 kB +195 B (+8%) 🔍
dotcom-rendering/dist/frontend.server.js 2.48 MB +773 B (0%)
dotcom-rendering/dist/MostViewedRightWrapper.legacy.js 4.07 kB +1 B (0%)
dotcom-rendering/dist/OnwardsLower.legacy.js 9.86 kB -1 B (0%)
dotcom-rendering/dist/OnwardsUpper.js 14 kB +1 B (0%)
dotcom-rendering/dist/OnwardsUpper.legacy.js 14.3 kB -2 B (0%)
dotcom-rendering/dist/react.js 139 kB -754 B (-1%)
dotcom-rendering/dist/react.legacy.js 145 kB -779 B (-1%)
ℹ️ View Unchanged
Filename Size
dotcom-rendering/dist/101.js 21.1 kB
dotcom-rendering/dist/101.legacy.js 21.1 kB
dotcom-rendering/dist/195.js 1.11 kB
dotcom-rendering/dist/195.legacy.js 1.23 kB
dotcom-rendering/dist/atomIframe.js 1.87 kB
dotcom-rendering/dist/atomIframe.legacy.js 2.13 kB
dotcom-rendering/dist/bootCmp.js 7.5 kB
dotcom-rendering/dist/bootCmp.legacy.js 11.1 kB
dotcom-rendering/dist/braze-web-sdk-core.js 36.1 kB
dotcom-rendering/dist/braze-web-sdk-core.legacy.js 36.1 kB
dotcom-rendering/dist/cmp.js 7.78 kB
dotcom-rendering/dist/coreVitals.js 4.03 kB
dotcom-rendering/dist/coreVitals.legacy.js 4.31 kB
dotcom-rendering/dist/dynamicImport.js 2.99 kB
dotcom-rendering/dist/dynamicImport.legacy.js 3.27 kB
dotcom-rendering/dist/EditionDropdown.js 685 B
dotcom-rendering/dist/EditionDropdown.legacy.js 694 B
dotcom-rendering/dist/elements-CalloutBlockComponent.js 4.15 kB
dotcom-rendering/dist/elements-DocumentBlockComponent.js 571 B
dotcom-rendering/dist/elements-DocumentBlockComponent.legacy.js 602 B
dotcom-rendering/dist/elements-InstagramBlockComponent.js 434 B
dotcom-rendering/dist/elements-InstagramBlockComponent.legacy.js 452 B
dotcom-rendering/dist/elements-InteractiveBlockComponent.js 2.96 kB
dotcom-rendering/dist/elements-InteractiveContentsBlockComponent.js 1.88 kB
dotcom-rendering/dist/elements-MapEmbedBlockComponent.js 1.88 kB
dotcom-rendering/dist/elements-MapEmbedBlockComponent.legacy.js 1.94 kB
dotcom-rendering/dist/elements-RichLinkComponent.js 3.26 kB
dotcom-rendering/dist/elements-RichLinkComponent.legacy.js 3.3 kB
dotcom-rendering/dist/elements-SpotifyBlockComponent.js 1.8 kB
dotcom-rendering/dist/elements-SpotifyBlockComponent.legacy.js 1.86 kB
dotcom-rendering/dist/elements-VideoFacebookBlockComponent.js 1.88 kB
dotcom-rendering/dist/elements-VideoFacebookBlockComponent.legacy.js 1.94 kB
dotcom-rendering/dist/elements-VineBlockComponent.js 579 B
dotcom-rendering/dist/elements-VineBlockComponent.legacy.js 594 B
dotcom-rendering/dist/embedIframe.js 1.88 kB
dotcom-rendering/dist/embedIframe.legacy.js 2.13 kB
dotcom-rendering/dist/ga.js 3.88 kB
dotcom-rendering/dist/ga.legacy.js 4.13 kB
dotcom-rendering/dist/GetMatchStats.js 3.29 kB
dotcom-rendering/dist/GetMatchStats.legacy.js 3.36 kB
dotcom-rendering/dist/guardian-braze-components-banner.js 9.78 kB
dotcom-rendering/dist/guardian-braze-components-banner.legacy.js 9.79 kB
dotcom-rendering/dist/guardian-braze-components-end-of-article.js 6.56 kB
dotcom-rendering/dist/guardian-braze-components-end-of-article.legacy.js 6.57 kB
dotcom-rendering/dist/MostViewedFooterData.js 6.27 kB
dotcom-rendering/dist/MostViewedFooterData.legacy.js 6.36 kB
dotcom-rendering/dist/MostViewedRightWrapper.js 3.89 kB
dotcom-rendering/dist/newsletterEmbedIframe.js 1.83 kB
dotcom-rendering/dist/newsletterEmbedIframe.legacy.js 2.08 kB
dotcom-rendering/dist/OnwardsLower.js 9.62 kB
dotcom-rendering/dist/ophan.js 7.17 kB
dotcom-rendering/dist/ophan.legacy.js 7.36 kB
dotcom-rendering/dist/relativeTime.js 2.41 kB
dotcom-rendering/dist/relativeTime.legacy.js 2.67 kB
dotcom-rendering/dist/sentry.js 677 B
dotcom-rendering/dist/sentry.legacy.js 687 B
dotcom-rendering/dist/sentryLoader.js 4.74 kB
dotcom-rendering/dist/sentryLoader.legacy.js 7.69 kB
dotcom-rendering/dist/shimport.js 2.75 kB
dotcom-rendering/dist/shimport.legacy.js 2.76 kB
dotcom-rendering/dist/SignInGateMain.js 1.82 kB
dotcom-rendering/dist/SignInGateMain.legacy.js 1.85 kB

compressed-size-action

Comment thread dotcom-rendering/src/web/components/App.tsx
@mxdvl

mxdvl commented Nov 18, 2021

Copy link
Copy Markdown
Contributor

As CMP is comparatively slow, I would be tempted to keep it very high up the priority list.

We need it to complete in order to do anything that requires consent, such as:

  • running ads
  • embedding YouTube iframes
  • accessing local storage

@oliverlloyd

Copy link
Copy Markdown
Contributor Author

We need it to complete in order to do anything that requires consent

Noted 👍

@oliverlloyd

Copy link
Copy Markdown
Contributor Author

Just making a note here that @OllysCoding spoke to me about the bundle size increase of 4Kb we're seeing here and suggested we look at dependency caching with webpack. We're going to pair on this tomorrow

@oliverlloyd
oliverlloyd marked this pull request as ready for review November 19, 2021 16:06
undefined,
);

useOnce(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just a hunch... although this will initiate CMP and set consent state on a second pass it won't block the render of YoutubeAtom on the first pass without consent.

YoutubeAtom will render its first and second pass (after its internal useEffect) without consent and therefore default to disabled ads.

Previously the HydrateOnce for YoutubeBlockComponent would waitFor={[consentState]}

I think...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @arelra. I think you're right. Previously we waited for consentState in App.tsx using a waitFor but we're not doing that here. I think I saw it suggested that we could fix this by making consentState a dependency for useOnce to run, which I think it true. This would essentially replicate the logic we had previously. Ahead of that though, I'm investigating if there are some optimisations that can be made in the YouTubeAtom itself. I'll update back here when I've done this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You might be already considering this but I think completely separating the overlay from the player will help reduce complexity of YoutubeAtom quite a bit and allow blocking of only whats required - i.e. instantiation of the player.

It will just need a method to trigger the play from the overlay to the player.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Based on this discussion, I looked deeper at how we render You Tube videos and discovered that we can improve how we do this.

@mchv pointed out a great lib to me earlier which defers the loading of the you tube javascript until the user clicks the poster overlay. My first response was to say that we already do this but when I looked more I realised we don't! So I've added this feature to our YouTubeAtom

guardian/atoms-rendering#303

Whilst doing this I also added a defer to wait for consentState which, if we're happy with that approach` would address the issues in this thread, without the need to manage waiting for state locally.

I'm also happy to put the waitFor in and not have YouTubeAtom manage this (we could make it required) or some combination of the both. Whichever api makes the best sense to the group is fine by me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is useOnce required if the dependency array is [] ?
If not you could just have a useEffect with [] ?

@oliverlloyd

Copy link
Copy Markdown
Contributor Author

Break out CMP

@kenoir

kenoir commented Nov 22, 2021

Copy link
Copy Markdown
Contributor

The T&C docs will need updating to point at this new location I think: https://github.com/guardian/transparency-consent-docs/blob/main/docs/in-the-browser.md

@oliverlloyd

Copy link
Copy Markdown
Contributor Author

The T&C docs will need updating to point at this new location I think: https://github.com/guardian/transparency-consent-docs/blob/main/docs/in-the-browser.md

Great point! Thanks for raising this

@oliverlloyd

Copy link
Copy Markdown
Contributor Author

The T&C docs will need updating to point at this new location

@kenoir I've created a PR to do this.

Comment thread dotcom-rendering/src/web/components/elements/YoutubeBlockComponent.tsx Outdated
Comment thread dotcom-rendering/src/web/components/elements/YoutubeBlockComponent.tsx Outdated
undefined,
);

useOnce(() => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is useOnce required if the dependency array is [] ?
If not you could just have a useEffect with [] ?

@oliverlloyd
oliverlloyd requested a review from arelra December 7, 2021 12:19
@oliverlloyd
oliverlloyd merged commit 91b706f into main Dec 9, 2021
@oliverlloyd
oliverlloyd deleted the oliver/remove-cmp-from-app branch December 9, 2021 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants