Skip to content

[WS-2680] - Unify polling hooks - #14327

Open
hotinglok wants to merge 16 commits into
latestfrom
WS-2680-create-generic-polling-hook
Open

[WS-2680] - Unify polling hooks#14327
hotinglok wants to merge 16 commits into
latestfrom
WS-2680-create-generic-polling-hook

Conversation

@hotinglok

@hotinglok hotinglok commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Resolves JIRA: WS-2680

Summary

Refactors the two hooks used for polling into one generic polling hook. What is done with the returned data is dealt with where the hook is called instead. This replaces useLivePagePolling and useSportDataPolling.

Please note that most of the files changed are deletions of the old hooks.

This PR supercedes #14324 which only refactored the makeRequest utility.

Code changes

  • Created generic usePolling hook which replaces useLivePagePolling and useSportDataPolling.
  • Refactored makeRequest into fetchPolledData - fetches directly from the polling endpoint for both Live page posts and sports header updates.
  • Removes transformers in useLivePagePolling now that they are done in FABL.
  • Updates consumers and moves some specific logic into where usePolling is now called (e.g. first post comparison logic in Live page).

Testing

Standard regression tests. This should not impact existing live pages.

Useful Links

Copilot AI left a comment

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.

Pull request overview

This PR introduces a single generic polling hook (usePolling) backed by a shared fetch utility (fetchPolledData), then migrates Live pages and the Sport “HeadToHeadV2” header to use it while removing the older, feature-specific polling hooks.

Changes:

  • Added src/app/hooks/usePolling (hook + docs + tests) and src/app/lib/utilities/fetchPolledData (utility + tests).
  • Migrated polling usage in Live pages (LivePageLayout) and Sport header (head-to-head-v2) to the new unified hook and updated associated tests.
  • Removed legacy polling hooks (useLivePagePolling, useSportDataPolling) and their related request/transformer helpers and tests.

Reviewed changes

Copilot reviewed 33 out of 38 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ws-nextjs-app/pages/[service]/live/[id]/livePolling.test.ts New hook-level tests for Live page polling behavior using usePolling.
ws-nextjs-app/pages/[service]/live/[id]/LivePageLayout.tsx Switch Live page polling logic from useLivePagePolling to usePolling.
ws-nextjs-app/pages/[service]/live/[id]/live.test.tsx Updates Live page tests to mock usePolling instead of useLivePagePolling.
ws-nextjs-app/pages/[service]/live/[id]/fixture/streamDataWithFlourish.js Adds a Live stream fixture (currently appears unused).
ws-nextjs-app/pages/[service]/live/[id]/fixture/streamDataUpdate.js Adds a Live stream update fixture used by new polling tests.
src/app/lib/utilities/fetchPolledData/index.ts New shared poll-data fetch utility (builds URL + logs + returns typed {data,status} or null).
src/app/lib/utilities/fetchPolledData/index.test.ts Unit tests for fetchPolledData success/failure paths.
src/app/hooks/useSportDataPolling/makeRequest/index.ts Removes legacy sport polling request helper.
src/app/hooks/useSportDataPolling/makeRequest/index.test.ts Removes tests for the legacy sport polling request helper.
src/app/hooks/useSportDataPolling/index.ts Removes legacy useSportDataPolling hook.
src/app/hooks/useSportDataPolling/index.test.ts Removes tests for legacy useSportDataPolling.
src/app/hooks/usePolling/README.md Adds documentation for the new unified polling hook (includes usage examples).
src/app/hooks/usePolling/index.ts Adds the new generic usePolling hook implementation.
src/app/hooks/usePolling/index.test.ts Adds unit tests for usePolling.
src/app/hooks/useLivePagePolling/transformers/handlePostBlocks/streamFixture.json Removes legacy Live page polling transformer fixture.
src/app/hooks/useLivePagePolling/transformers/handlePostBlocks/index.ts Removes legacy Live page polling transformer.
src/app/hooks/useLivePagePolling/transformers/handlePostBlocks/index.test.ts Removes tests for legacy transformer.
src/app/hooks/useLivePagePolling/transformers/handleEmptyParagraphBlocks/index.ts Removes legacy Live page polling transformer.
src/app/hooks/useLivePagePolling/transformers/handleEmptyParagraphBlocks/index.test.ts Removes tests for legacy transformer.
src/app/hooks/useLivePagePolling/transformers/handleCustomEmbed/providerMarkup.ts Removes legacy Live page polling custom-embed markup generator.
src/app/hooks/useLivePagePolling/transformers/handleCustomEmbed/index.ts Removes legacy Live page polling custom-embed transformer.
src/app/hooks/useLivePagePolling/transformers/handleCustomEmbed/index.test.ts Removes tests for legacy transformer.
src/app/hooks/useLivePagePolling/transformers/enrichVivoEmbed/index.ts Removes legacy Live page polling embed enrichment transformer.
src/app/hooks/useLivePagePolling/transformers/enrichVivoEmbed/index.test.ts Removes tests for legacy transformer.
src/app/hooks/useLivePagePolling/transformers/addIndexesToEmbeds/index.ts Removes legacy Live page polling embed indexing transformer.
src/app/hooks/useLivePagePolling/transformers/addIndexesToEmbeds/index.test.ts Removes tests for legacy transformer.
src/app/hooks/useLivePagePolling/transformers/addFullHeightToFlourishSrc/index.ts Removes legacy Live page polling Flourish iframe transformer.
src/app/hooks/useLivePagePolling/transformers/addFullHeightToFlourishSrc/index.test.ts Removes tests for legacy transformer.
src/app/hooks/useLivePagePolling/makeRequest/makeRequest.ts Removes legacy Live page polling request helper.
src/app/hooks/useLivePagePolling/makeRequest/makeRequest.test.ts Removes tests for legacy Live page polling request helper.
src/app/hooks/useLivePagePolling/index.ts Removes legacy useLivePagePolling hook.
src/app/hooks/useLivePagePolling/index.test.ts Removes tests for legacy useLivePagePolling.
src/app/components-webcore/SportDataHeader/head-to-head-v2/tests/polling.test.ts New tests verifying sport header polling behavior via usePolling.
src/app/components-webcore/SportDataHeader/head-to-head-v2/tests/index.test.tsx Updates HeadToHeadV2 component tests to mock usePolling.
src/app/components-webcore/SportDataHeader/head-to-head-v2/head-to-head-v2.tsx Migrates sport header polling from useSportDataPolling to usePolling.
src/app/components-webcore/SportDataHeader/head-to-head-v2/fixture/sportDataUpdate.js Adds sport polling “updated” fixture for the new polling tests.
src/app/components-webcore/SportDataHeader/head-to-head-v2/fixture/sportData.js Adds sport polling “initial” fixture for the new polling tests.
Suppressed comments (2)

src/app/hooks/usePolling/README.md:21

  • The usage example URL-encodes sportDataEventUrn, but fetchPolledData uses URLSearchParams.append which encodes values again. This can double-encode URNs (e.g. %3A -> %253A) and break the request. The example should pass the raw URN instead.
  initialData: initialSportData,
  enabled: Boolean(sportHeaderPollEnabled) && isSportDataLive,
  endpoint: 'sport',
  params: { sportDataEventUrn: encodeURIComponent(initialSportData.urn) },
  returnedData: response => response.sportDataEvent,

src/app/hooks/usePolling/index.test.ts:62

  • This assertion also expects an already-encoded sportDataEventUrn. If fetchPolledData encodes via URLSearchParams, the correct contract is to pass a raw URN and let the utility encode once.
    expect(fetchSpy).toHaveBeenCalledWith('sport', {
      params: { sportDataEventUrn: encodeURIComponent('urn:sport:123') },
    });

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/app/hooks/usePolling/README.md Outdated
Comment thread src/app/hooks/usePolling/index.test.ts
Comment thread src/app/components-webcore/SportDataHeader/head-to-head-v2/tests/polling.test.ts Outdated
@hotinglok
hotinglok marked this pull request as ready for review August 19, 2026 14:50
Comment thread ws-nextjs-app/pages/[service]/live/[id]/LivePageLayout.tsx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants