Skip to content

WS-2769 - Update Inline JS: NextJs - #14323

Open
louisearchibald wants to merge 21 commits into
latestfrom
WS-2769-update-inline-JS-nextJS
Open

WS-2769 - Update Inline JS: NextJs#14323
louisearchibald wants to merge 21 commits into
latestfrom
WS-2769-update-inline-JS-nextJS

Conversation

@louisearchibald

@louisearchibald louisearchibald commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Resolves JIRA: WS-2769

Summary

Extracts inline JS code in the next app into separate functions to bring this inline with our coding standards.

Code changes

  • Extracts the logic responsible for setting client-side environment variables into setSimorghEnvVars and updates the existing inline script to use the extracted function.
  • Extracts the logic responsible for removing the no-js class into removeNoJsClass and updates the existing inline script to use the extracted function.
  • Uses traditional function syntax to maintain compatibility with Opera Mini when the functions are converted to strings and executed inline.

Testing

  1. Tested this both locally using environment builds, and also using an opera-mini emulator. Have documented testing steps in a log in the description of this ticket: https://bbc.atlassian.net/browse/WS-2772

@louisearchibald louisearchibald self-assigned this Aug 18, 2026
@louisearchibald
louisearchibald marked this pull request as ready for review August 21, 2026 14:08
Copilot AI lite review requested due to automatic review settings August 21, 2026 14:08

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 refactors inline JavaScript in the Next.js document to use extracted utility functions, aiming to align with Simorgh coding standards while keeping Opera Mini compatibility when function bodies are stringified and executed inline.

Changes:

  • Extracts the “remove no-js class” inline script into removeNoJsClass and invokes it via toString() in _document.
  • Extracts client-side env var bootstrap logic into setSimorghEnvVars and invokes it inline with serialized env vars.
  • Updates _document.page.tsx to use the new utilities.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
ws-nextjs-app/pages/_document.page.tsx Replaces inline JS snippets with stringified calls to extracted utility functions.
src/app/lib/utilities/setSimorghEnvVars/index.tsx Adds a utility to set window.SIMORGH_ENV_VARS from server-provided values.
src/app/lib/utilities/removeNoJsClass/index.tsx Adds a utility to remove the no-js class from the root element early in page load.

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

Comment thread src/app/lib/utilities/setSimorghEnvVars/index.tsx Outdated
Comment thread src/app/lib/utilities/setSimorghEnvVars/index.tsx
Comment thread src/app/lib/utilities/removeNoJsClass/index.tsx
@holchris holchris self-assigned this Aug 25, 2026

@pvaliani pvaliani 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.

Looks good!

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.

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.

I've updated this now too, thanks for spotting. 🙏

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.

6 participants