Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions dotcom-rendering/src/components/InteractiveAtom.tsx
Copy link
Contributor

Choose a reason for hiding this comment

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

The description above says (emphasis mine):

As per #14140 the changes here currently apply to interactive elements but not atoms.

But this is the component for interactive atoms?

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { css } from '@emotion/react';
import { getInteractionClient } from '../lib/bridgetApi';
import { unifyPageContent } from '../lib/unifyPageContent';
import { palette } from '../palette';
import { useConfig } from './ConfigContext';
Expand Down Expand Up @@ -47,11 +48,18 @@ export const InteractiveAtom = ({
}: InteractiveAtomType) => {
const { renderingTarget } = useConfig();

const isApps = renderingTarget === 'Apps';

const onTouchStart = () => getInteractionClient().disableArticleSwipe(true);
const onTouchEnd = () => getInteractionClient().disableArticleSwipe(false);

return (
<div
css={[containerStyles, !!isMainMedia && fullHeightStyles]}
data-atom-id={id}
data-atom-type="interactive"
onTouchStart={isApps ? onTouchStart : undefined}
onTouchEnd={isApps ? onTouchEnd : undefined}
Copy link
Contributor

@JamieB-gu JamieB-gu Sep 19, 2025

Choose a reason for hiding this comment

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

This doesn't appear to be wrapped in an Island, so what allows this code to run on the client?

>
<Island
priority="feature"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import libDebounce from 'lodash.debounce';
import { useRef, useState } from 'react';
import { interactiveLegacyFigureClasses } from '../layouts/lib/interactiveLegacyStyling';
import { type ArticleFormat, ArticleSpecial } from '../lib/articleFormat';
import { getInteractionClient } from '../lib/bridgetApi';
import { useOnce } from '../lib/useOnce';
import { palette as themePalette } from '../palette';
import type { RoleType } from '../types/content';
Expand Down Expand Up @@ -349,6 +350,12 @@ export const InteractiveBlockComponent = ({
? true
: false;

const isApps = renderingTarget === 'Apps';

const onTouchStart = () => getInteractionClient().disableArticleSwipe(true);

const onTouchEnd = () => getInteractionClient().disableArticleSwipe(false);
Copy link
Member

Choose a reason for hiding this comment

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

Small performance suggestion.

I think these functions will be created on every render of this component even though they may not be used by the web rendering target. We could inline them in but again they will be created on every render of the component. useCallback is an option but given the functions are idempotent and afaics don't rely on any state could they be moved outside of the component to the module level?


useOnce(() => {
// We've brought the behavior from boot.js into this file to avoid loading 2 extra scripts

Expand Down Expand Up @@ -455,6 +462,8 @@ export const InteractiveBlockComponent = ({
data-alt={alt} // for compatibility with custom boot scripts
data-testid={`interactive-element-${encodeURI(alt ?? '')}`}
data-spacefinder-role={role}
onTouchStart={isApps ? onTouchStart : undefined}
onTouchEnd={isApps ? onTouchEnd : undefined}
>
{!loaded && (
<>
Expand Down