diff --git a/dotcom-rendering/index.d.ts b/dotcom-rendering/index.d.ts index 9f33fd83e70..313ae4a31ca 100644 --- a/dotcom-rendering/index.d.ts +++ b/dotcom-rendering/index.d.ts @@ -880,11 +880,6 @@ interface VineBlockLoadable extends ComponentNameChunkMap { addWhen: VineBlockElement['_type']; } -interface InstagramBlockLoadable extends ComponentNameChunkMap { - chunkName: 'InstagramBlockComponent'; - addWhen: InstagramBlockElement['_type']; -} - // There are docs on loadable in ./docs/loadable-components.md type LoadableComponents = [ YoutubeBlockLoadable, @@ -897,7 +892,6 @@ type LoadableComponents = [ SpotifyBlockLoadable, FacebookVideoBlockLoadable, VineBlockLoadable, - InstagramBlockLoadable, ]; interface CarouselImagesMap { diff --git a/dotcom-rendering/src/web/components/App.tsx b/dotcom-rendering/src/web/components/App.tsx index 687d1fe7cb3..75ada0af933 100644 --- a/dotcom-rendering/src/web/components/App.tsx +++ b/dotcom-rendering/src/web/components/App.tsx @@ -458,26 +458,6 @@ export const App = ({ CAPI, ophanRecord }: Props) => { }, ); - const InstagramBlockComponent = loadable( - () => { - if ( - CAPI.elementsToHydrate.filter( - (element) => - element._type === - 'model.dotcomrendering.pageElements.InstagramBlockElement', - ).length > 0 - ) { - return import( - '@frontend/web/components/InstagramBlockComponent' - ); - } - return Promise.reject(); - }, - { - resolveComponent: (module) => module.InstagramBlockComponent, - }, - ); - // We use this function to filter the elementsToHydrate array by a particular // type so that we can hydrate them. We use T to force the type and keep TS // content because *we* know that if _type equals a thing then the type is @@ -531,10 +511,6 @@ export const App = ({ CAPI, ophanRecord }: Props) => { CAPI.elementsToHydrate, 'model.dotcomrendering.pageElements.EmbedBlockElement', ); - const instas = elementsByType( - CAPI.elementsToHydrate, - 'model.dotcomrendering.pageElements.InstagramBlockElement', - ); const maps = elementsByType( CAPI.elementsToHydrate, 'model.dotcomrendering.pageElements.MapBlockElement', @@ -908,26 +884,6 @@ export const App = ({ CAPI, ophanRecord }: Props) => { )} ))} - {instas.map((insta, index) => ( - - - updateIframeHeight( - `iframe[name="instagram-embed-${index}"]`, - ) - } - > - - - - ))} {maps.map((map) => ( {

- - updateIframeHeight( - 'iframe[name="instagram-embed-1"]', - ) - } - > - - +

The end.

, diff --git a/dotcom-rendering/src/web/components/InstagramBlockComponent.importable.tsx b/dotcom-rendering/src/web/components/InstagramBlockComponent.importable.tsx new file mode 100644 index 00000000000..1ddcdd1e988 --- /dev/null +++ b/dotcom-rendering/src/web/components/InstagramBlockComponent.importable.tsx @@ -0,0 +1,42 @@ +import { css } from '@emotion/react'; +import { updateIframeHeight } from '../browser/updateIframeHeight'; +import { ClickToView } from './ClickToView'; + +const fullWidthStyles = css` + width: 100%; +`; + +/** + * Note the iframe created in this component is dependent on the embedIFrame function being + * called to be size correctly. + * src/web/browser/embedIframe/embedIframe.ts + */ +export const InstagramBlockComponent: React.FC<{ + element: InstagramBlockElement; + index: number; + isMainMedia: boolean; +}> = ({ element, index, isMainMedia }) => { + return ( + + updateIframeHeight(`iframe[name="instagram-embed-${index}"]`) + } + > +