Skip to content

CSS Modules - Support AMP and Lite rendering#13992

Merged
andrewscfc merged 44 commits into
andrew-scss-modulesfrom
andrew-scss-modules_fix-amp-lite-css
Jun 3, 2026
Merged

CSS Modules - Support AMP and Lite rendering#13992
andrewscfc merged 44 commits into
andrew-scss-modulesfrom
andrew-scss-modules_fix-amp-lite-css

Conversation

@andrewscfc
Copy link
Copy Markdown
Contributor

@andrewscfc andrewscfc commented May 7, 2026

Resolves JIRA: N/A

Summary

This PR addresses @HarveyPeachey 's observation around how our other rendering strategies work with the new css modules approach:

Wonder how this affects our rendering strategies like lite site as well

The approach is explained in the docs accompanying this change: ws-nextjs-app/docs/amp-lite-css-extraction.md

Also with regards to @amoore108 's suggestion:

Also worth testing with JS disabled to see how it behaves with just the server-render.

CSS with JS disabled does work with JS disabled for the production build on canonical but not for the dev build; this is a limitation of next's dev server implementation that I didn't feel it was necessary to workaround.

Useful Links

Co-authored-by: Copilot <copilot@github.com>
@andrewscfc andrewscfc changed the base branch from latest to andrew-scss-modules May 7, 2026 16:11
Comment thread ws-nextjs-app/pages/_document.page.tsx Outdated
andrewscfc and others added 19 commits May 8, 2026 11:53
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…opilot]

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@andrewscfc andrewscfc marked this pull request as ready for review May 22, 2026 08:57
Copilot AI review requested due to automatic review settings May 22, 2026 08:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an AMP/Lite CSS inlining mechanism for the Next.js app so that CSS Modules styles are available during SSR (where external stylesheets can’t be used), covering both dev and production flows.

Changes:

  • Introduces getAmpLiteCss to inline CSS for AMP/Lite by reading from Next manifests in production and a dev-only extracted CSS file in development.
  • Adds a dev-only webpack loader (DevCssExtractLoader) to extract css-loader output to build/dev-css-modules.css, and injects it via next.config.js.
  • Wires AMP/Lite render paths in _document.page.tsx to append extracted CSS, plus adds supporting tests, docs, and log codes.

Reviewed changes

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

Show a summary per file
File Description
ws-nextjs-app/utilities/getAmpLiteCss/index.ts Implements AMP/Lite CSS resolution and inlining (dev + prod) using manifests / extracted file.
ws-nextjs-app/utilities/getAmpLiteCss/index.test.ts Unit tests for the AMP/Lite CSS resolution, manifest parsing, and error handling.
ws-nextjs-app/scripts/DevCssExtractLoader.cjs Custom dev-only webpack loader to extract hashed CSS Modules CSS from css-loader output.
ws-nextjs-app/scripts/DevCssExtractLoader.test.ts Unit tests validating loader extraction behavior and disk writes.
ws-nextjs-app/pages/_document.page.tsx Appends extracted CSS to AMP and Lite render branches using __NEXT_DATA__.
ws-nextjs-app/next.config.js Injects the dev CSS extraction loader before css-loader in dev builds.
ws-nextjs-app/docs/amp-lite-css-extraction.md Documents rationale and approach for AMP/Lite CSS extraction in dev and prod.
src/app/lib/logger.const.js Adds new log codes for manifest/CSS extraction read errors.

Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts
Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts
Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts Outdated
@andrewscfc andrewscfc changed the title Andrew scss modules fix amp lite css CSS Modules - Support AMP and Lite rendering May 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Comment thread ws-nextjs-app/docs/amp-lite-css-extraction.md Outdated
…lot]

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts
Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts Outdated
Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts
… across environments and update documentation for clarity [copilot]
@andrewscfc andrewscfc requested a review from a team as a code owner May 28, 2026 09:53
@andrewscfc andrewscfc requested a review from Copilot May 28, 2026 09:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts
Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.

Comment thread ws-nextjs-app/utilities/getAmpLiteCss/index.ts
Copy link
Copy Markdown
Member

@elvinasv elvinasv left a comment

Choose a reason for hiding this comment

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

Clever solution!

Probably this was discussed already, but given the complexity of handling Lite/AMP dev server/HMR and the associated maintenance, could we skip dev server support for AMP/Lite and just use a production build (i.e. yarn build:local)? Would simplify this quite a bit.

dynamicIds: Array<string | number>;
}): string => {
const isProd = process.env.NODE_ENV === 'production';
const devCssPath = join(process.cwd(), 'build/dev-css-modules.css');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: potentially we could read the file name from a shared constant?

const OUTPUT_FILE = 'build/dev-css-modules.css';

@andrewscfc
Copy link
Copy Markdown
Contributor Author

Clever solution!

Probably this was discussed already, but given the complexity of handling Lite/AMP dev server/HMR and the associated maintenance, could we skip dev server support for AMP/Lite and just use a production build (i.e. yarn build:local)? Would simplify this quite a bit.

Funnily enough, this was my initial conclusion, I've obviously done a big experiment with AI in this PR as I couldn't have done the dev server in a reasonable time without it.

Now although it seems to work, do you think it's worth pulling out now due to the long term maintenance?

Copy link
Copy Markdown
Member

@elvinasv elvinasv left a comment

Choose a reason for hiding this comment

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

Personally I’m fine with not using HMR for AMP/Lite, but it might be worth consulting engineers who work with more the Lite site.

@andrewscfc andrewscfc merged commit 53ded42 into andrew-scss-modules Jun 3, 2026
10 of 11 checks passed
@andrewscfc andrewscfc deleted the andrew-scss-modules_fix-amp-lite-css branch June 3, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants