Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dotcom-rendering/src/components/InteractiveAtom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const InteractiveAtom = ({
css={[containerStyles, !!isMainMedia && fullHeightStyles]}
data-atom-id={id}
data-atom-type="interactive"
{...(customData ? { 'data-atom-custom-data': customData } : {})}
>
<Island
priority="feature"
Expand All @@ -70,6 +69,7 @@ export const InteractiveAtom = ({
elementCss,
elementHtml,
renderingTarget,
customData,
})}
frameBorder="0"
/>
Expand Down
16 changes: 8 additions & 8 deletions dotcom-rendering/src/lib/interactiveAtoms.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { InteractiveLayoutAtom } from '../components/InteractiveLayoutAtom';
const mockCustomData = JSON.stringify({ key: 'value' });

describe('Interactive atom custom data attributes', () => {
it('should add custom data attribute to InteractiveAtom on web', () => {
it('should inject custom data into srcDoc for InteractiveAtom on web', () => {
const { container } = render(
<ConfigProvider
value={{
Expand All @@ -23,13 +23,13 @@ describe('Interactive atom custom data attributes', () => {
/>
</ConfigProvider>,
);
const el = container.querySelector(
`[data-atom-custom-data='${mockCustomData}']`,
const iframe = container.querySelector('iframe');
expect(iframe?.srcdoc).toContain(
`window.__atomCustomData = ${mockCustomData}`,
);
expect(el).toBeInTheDocument();
});

it('should add custom data attribute to InteractiveAtom on apps', () => {
it('should inject custom data into srcDoc for InteractiveAtom on apps', () => {
const { container } = render(
<ConfigProvider
value={{
Expand All @@ -46,10 +46,10 @@ describe('Interactive atom custom data attributes', () => {
/>
</ConfigProvider>,
);
const el = container.querySelector(
`[data-atom-custom-data='${mockCustomData}']`,
const iframe = container.querySelector('iframe');
expect(iframe?.srcdoc).toContain(
`window.__atomCustomData = ${mockCustomData}`,
);
expect(el).toBeInTheDocument();
});

it('should add custom data attribute to InteractiveLayoutAtom', () => {
Expand Down
9 changes: 9 additions & 0 deletions dotcom-rendering/src/lib/unifyPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export const unifyPageContent = ({
elementJs,
elementHtml,
renderingTarget,
customData,
}: {
elementCss?: string;
elementJs?: string;
elementHtml?: string;
renderingTarget: RenderingTarget;
customData?: string;
}): string =>
renderToString(
<html lang="en">
Expand All @@ -29,6 +31,13 @@ export const unifyPageContent = ({
<div dangerouslySetInnerHTML={{ __html: elementHtml }} />
)}
</body>
{!!customData && (
<script
dangerouslySetInnerHTML={{
__html: `window.__atomCustomData = ${customData};`,
}}
/>
)}
{/* JS need to load on body render */}
{!!elementJs && (
<script dangerouslySetInnerHTML={{ __html: elementJs }} />
Expand Down
Loading