Skip to content

Braze - #3923

Closed
oliverlloyd wants to merge 3 commits into
mainfrom
oliver/braze-component
Closed

Braze#3923
oliverlloyd wants to merge 3 commits into
mainfrom
oliver/braze-component

Conversation

@oliverlloyd

Copy link
Copy Markdown
Contributor

What does this change?

This PR introduces Braze a component designed to hold the shared logic between SlotBodyEnd and StickyBottomBanner

Why?

Because I think this is the safest refactor in order to make progress towards deleting App.tsx. It probably is possible to isolate each of these components and remove the global state shared between them but this logic is complex and I decided to take this approach as a stepping stone towards this goal instead of diving in.

slot-body-end

This id was previously used by the Portal component as the marker for where to insert the element. But it has also been picked up as an id that can be used for some css styling. By removing the Portal I would break this styling code so I have added an aside wrapper around the component.

bannerWrapper

This css previously existed in the stickiness lib and was added in the layout files. I've moved it down into the banner component directly as this seemed the more logical location for this code.

shouldShowSlotBodyEnd

Previously we rendered the SlotBodyEnd and StickyBottomBanner components independently but they did not always appear together. For Interactive and FullPageInteractive articles SlotBodyEnd is not included and we also checked some flags. This function encapsulates this logic.

@github-actions github-actions Bot added the dotcom label Feb 4, 2022
@@ -1,14 +1,12 @@
import React, { useState, useEffect } from 'react';
import React, { useEffect } from 'react';

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.

🎉

Comment on lines +42 to +43
if (!switches.slotBodyEnd) return false;
if (!parse(slotMachineFlags || '').showBodyEnd) return false;

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.

Could somebody please check that this code is the same as:

	const showBodyEndSlot =
		parse(CAPI.slotMachineFlags || '').showBodyEnd ||
		CAPI.config.switches.slotBodyEnd;

This parse function is hard to reason about

@jamesgorrie jamesgorrie Feb 8, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The logic looks the same in each case. Your version of splitting into separate conditions is clearer.

bikeshed: A tiny slot-machine-flags.test could be useful.

What is the source of CAPI.slotMachineFlags & CAPI.config.switches?

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.

What is the source of CAPI.slotMachineFlags & CAPI.config.switches?

I'm honestly not sure. I think switches maybe come from a tool around Composer? slotMachineFlags I know nothing about @sndrs any ideas?

@github-actions

github-actions Bot commented Feb 4, 2022

Copy link
Copy Markdown

Size Change: -79.8 kB (-7%) ✅

Total Size: 1.1 MB

Filename Size Change
dotcom-rendering/dist/1376.legacy.js 3.82 kB +2 B (0%)
dotcom-rendering/dist/343.js 3.72 kB -8 B (0%)
dotcom-rendering/dist/343.legacy.js 3.91 kB +2 B (0%)
dotcom-rendering/dist/3777.legacy.js 6.42 kB +4 B (0%)
dotcom-rendering/dist/4415.legacy.js 3.55 kB -4 B (0%)
dotcom-rendering/dist/45.legacy.js 3.55 kB -4 B (0%)
dotcom-rendering/dist/7317.js 3.39 kB -9 B (0%)
dotcom-rendering/dist/7489.js 3.39 kB -9 B (0%)
dotcom-rendering/dist/7754.legacy.js 3.55 kB -4 B (0%)
dotcom-rendering/dist/8080.js 3.51 kB -4 B (0%)
dotcom-rendering/dist/8080.legacy.js 3.7 kB +1 B (0%)
dotcom-rendering/dist/8497.js 4 kB -5 B (0%)
dotcom-rendering/dist/9212.js 3.39 kB -9 B (0%)
dotcom-rendering/dist/braze-web-sdk-core.js 0 B -36.1 kB (removed) 🏆
dotcom-rendering/dist/braze-web-sdk-core.legacy.js 0 B -36.1 kB (removed) 🏆
dotcom-rendering/dist/cmp.js 0 B -7.51 kB (removed) 🏆
dotcom-rendering/dist/frontend.server.js 335 kB +35.6 kB (+12%) ⚠️
dotcom-rendering/dist/guardian-braze-components-banner.js 10.7 kB +133 B (+1%)
dotcom-rendering/dist/guardian-braze-components-banner.legacy.js 0 B -10.6 kB (removed) 🏆
dotcom-rendering/dist/guardian-braze-components-end-of-article.js 7.55 kB +940 B (+14%) ⚠️
dotcom-rendering/dist/guardian-braze-components-end-of-article.legacy.js 0 B -6.62 kB (removed) 🏆
dotcom-rendering/dist/react.js 77.4 kB -9.09 kB (-11%) 👏
dotcom-rendering/dist/react.legacy.js 82.5 kB -10.7 kB (-11%) 👏
dotcom-rendering/dist/readerRevenueDevUtils.js 893 B +2 B (0%)
dotcom-rendering/dist/readerRevenueDevUtils.legacy.js 955 B +3 B (0%)
dotcom-rendering/dist/SignInGateMain.js 1.84 kB +1 B (0%)
dotcom-rendering/dist/SignInGateMain.legacy.js 1.88 kB +1 B (0%)
dotcom-rendering/dist/YoutubeBlockComponent.js 2.93 kB +91 B (+3%)
dotcom-rendering/dist/YoutubeBlockComponent.legacy.js 3.09 kB +120 B (+4%)
ℹ️ View Unchanged
Filename Size
dotcom-rendering/dist/1376.js 3.63 kB
dotcom-rendering/dist/1672.js 3.72 kB
dotcom-rendering/dist/1924.js 4.56 kB
dotcom-rendering/dist/1924.legacy.js 4.7 kB
dotcom-rendering/dist/1983.js 13.8 kB
dotcom-rendering/dist/1983.legacy.js 14.4 kB
dotcom-rendering/dist/2666.js 30.6 kB
dotcom-rendering/dist/3213.js 13 kB
dotcom-rendering/dist/3213.legacy.js 13.2 kB
dotcom-rendering/dist/3215.js 4.88 kB
dotcom-rendering/dist/3215.legacy.js 5.05 kB
dotcom-rendering/dist/3321.legacy.js 28.5 kB
dotcom-rendering/dist/3397.js 240 B
dotcom-rendering/dist/3397.legacy.js 251 B
dotcom-rendering/dist/3639.js 4.62 kB
dotcom-rendering/dist/3639.legacy.js 4.81 kB
dotcom-rendering/dist/4576.js 235 B
dotcom-rendering/dist/4576.legacy.js 247 B
dotcom-rendering/dist/4850.js 235 B
dotcom-rendering/dist/4850.legacy.js 246 B
dotcom-rendering/dist/4999.js 17.9 kB
dotcom-rendering/dist/4999.legacy.js 18.5 kB
dotcom-rendering/dist/5217.js 233 B
dotcom-rendering/dist/5217.legacy.js 245 B
dotcom-rendering/dist/53.js 4.11 kB
dotcom-rendering/dist/53.legacy.js 4.12 kB
dotcom-rendering/dist/5373.legacy.js 3.58 kB
dotcom-rendering/dist/5585.js 5.2 kB
dotcom-rendering/dist/5585.legacy.js 5.36 kB
dotcom-rendering/dist/602.js 8.66 kB
dotcom-rendering/dist/602.legacy.js 8.92 kB
dotcom-rendering/dist/6348.js 4.58 kB
dotcom-rendering/dist/6348.legacy.js 4.75 kB
dotcom-rendering/dist/6372.legacy.js 3.89 kB
dotcom-rendering/dist/6400.js 21.5 kB
dotcom-rendering/dist/6400.legacy.js 21.5 kB
dotcom-rendering/dist/6684.js 241 B
dotcom-rendering/dist/6684.legacy.js 252 B
dotcom-rendering/dist/6916.js 8.25 kB
dotcom-rendering/dist/6916.legacy.js 8.71 kB
dotcom-rendering/dist/6965.js 2.65 kB
dotcom-rendering/dist/6965.legacy.js 2.71 kB
dotcom-rendering/dist/7051.js 7.22 kB
dotcom-rendering/dist/7051.legacy.js 7.37 kB
dotcom-rendering/dist/8294.js 232 B
dotcom-rendering/dist/8294.legacy.js 244 B
dotcom-rendering/dist/8330.js 3.21 kB
dotcom-rendering/dist/8748.js 232 B
dotcom-rendering/dist/8748.legacy.js 243 B
dotcom-rendering/dist/9641.js 5.17 kB
dotcom-rendering/dist/9641.legacy.js 5.34 kB
dotcom-rendering/dist/9776.js 5.09 kB
dotcom-rendering/dist/9776.legacy.js 5.26 kB
dotcom-rendering/dist/9884.js 17 kB
dotcom-rendering/dist/9884.legacy.js 17.3 kB
dotcom-rendering/dist/atomIframe.js 1.87 kB
dotcom-rendering/dist/atomIframe.legacy.js 2.14 kB
dotcom-rendering/dist/bootCmp.js 7.39 kB
dotcom-rendering/dist/bootCmp.legacy.js 10.9 kB
dotcom-rendering/dist/coreVitals.js 4.03 kB
dotcom-rendering/dist/coreVitals.legacy.js 4.33 kB
dotcom-rendering/dist/dynamicImport.js 3 kB
dotcom-rendering/dist/dynamicImport.legacy.js 3.29 kB
dotcom-rendering/dist/embedIframe.js 1.88 kB
dotcom-rendering/dist/embedIframe.legacy.js 2.14 kB
dotcom-rendering/dist/ga.js 3.88 kB
dotcom-rendering/dist/ga.legacy.js 4.14 kB
dotcom-rendering/dist/initDiscussion.js 7.46 kB
dotcom-rendering/dist/initDiscussion.legacy.js 7.71 kB
dotcom-rendering/dist/InteractiveBlockComponent.js 2.99 kB
dotcom-rendering/dist/InteractiveBlockComponent.legacy.js 3.12 kB
dotcom-rendering/dist/islands.js 7.61 kB
dotcom-rendering/dist/islands.legacy.js 8.36 kB
dotcom-rendering/dist/MostViewedFooterData.js 6.25 kB
dotcom-rendering/dist/MostViewedFooterData.legacy.js 6.34 kB
dotcom-rendering/dist/newsletterEmbedIframe.js 1.83 kB
dotcom-rendering/dist/newsletterEmbedIframe.legacy.js 2.1 kB
dotcom-rendering/dist/ophan.js 7.18 kB
dotcom-rendering/dist/ophan.legacy.js 7.38 kB
dotcom-rendering/dist/relativeTime.js 2.41 kB
dotcom-rendering/dist/relativeTime.legacy.js 2.68 kB
dotcom-rendering/dist/sentry.js 677 B
dotcom-rendering/dist/sentry.legacy.js 689 B
dotcom-rendering/dist/sentryLoader.js 4.75 kB
dotcom-rendering/dist/sentryLoader.legacy.js 7.71 kB
dotcom-rendering/dist/shimport.js 2.75 kB
dotcom-rendering/dist/shimport.legacy.js 2.76 kB

compressed-size-action

}
}

export const Braze = ({

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.

Pulling this out of App looks great. I'm not sure Braze is the right name here, as SlotBodyEnd and StickyBottomBanner are broader than just Braze (they may also show epics/banners from RRCP and also the CMP banner). Not sure what a good name is that ties those two slots together though (maybe this is what Automat is 😄 )

@oliverlloyd

Copy link
Copy Markdown
Contributor Author

Closing now that we have #4126 🎉

@oliverlloyd oliverlloyd closed this Mar 2, 2022
@shtukas
shtukas deleted the oliver/braze-component branch February 1, 2023 12:19
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.

3 participants