Skip to content

docs(cookbook): add SSG and CSP considerations to theme management#8231

Merged
gioboa merged 3 commits intoQwikDev:mainfrom
chindris-mihai-alexandru:docs/theme-management-ssg-csp
Jan 15, 2026
Merged

docs(cookbook): add SSG and CSP considerations to theme management#8231
gioboa merged 3 commits intoQwikDev:mainfrom
chindris-mihai-alexandru:docs/theme-management-ssg-csp

Conversation

@chindris-mihai-alexandru
Copy link
Copy Markdown
Contributor

Summary

This PR expands the Theme Management cookbook with practical guidance for common production scenarios:

  • SSG (Static Site Generation) considerations: Explains why inline scripts are needed for SSG deployments and why useVisibleTask$ alone causes theme flicker
  • useVisibleTask$ with document-ready strategy: Shows how to sync toggle button state after hydration without causing flicker
  • CSP (Content Security Policy) considerations: Documents three approaches (unsafe-inline, nonces for SSR, script hashes)
  • Complete SSG example: Full root.tsx setup for Cloudflare Pages and similar static hosts
  • Troubleshooting section: Common issues (flicker, wrong toggle state, CSP errors) and solutions

This addresses the patterns discussed in closed issue #3391 (dark mode flicker) by documenting the recommended solutions that the community discovered.

Type of change

  • Documentation update

Checklist

Copilot AI review requested due to automatic review settings January 9, 2026 17:53
@chindris-mihai-alexandru chindris-mihai-alexandru requested a review from a team as a code owner January 9, 2026 17:53
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 9, 2026

⚠️ No Changeset found

Latest commit: 4297872

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown

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

This PR significantly expands the Theme Management cookbook with comprehensive guidance for production scenarios. It addresses common challenges with dark mode implementation in Qwik applications, particularly for Static Site Generation (SSG) deployments and Content Security Policy (CSP) compliance.

Key changes include:

  • Complete rewrite with improved clarity and modern JavaScript practices
  • Detailed explanations of SSG considerations and why inline scripts prevent theme flicker
  • Documentation of three CSP approaches (unsafe-inline, nonces, and script hashes)
  • Multiple code examples showing different implementation patterns
  • New troubleshooting section for common issues

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx
- Change var to const in inline scripts
- Use classList.add/remove instead of className for consistency
- Add aria-hidden to decorative SVG icons
- Add note about ThemeToggle component reuse in complete example
- Add security note about unsafe-inline trade-offs
- Add comment explaining ThemeToggle placement
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 9, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@builder.io/qwik@8231
npm i https://pkg.pr.new/@builder.io/qwik-city@8231
npm i https://pkg.pr.new/eslint-plugin-qwik@8231
npm i https://pkg.pr.new/create-qwik@8231

commit: 4297872

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 4297872

Copy link
Copy Markdown
Member

@maiieul maiieul left a comment

Choose a reason for hiding this comment

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

Thanks @chindris-mihai-alexandru good additions and improvements overall. Can you address my comments before I click the merge button? 🤓

Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
Comment thread packages/docs/src/routes/docs/cookbook/theme-management/index.mdx Outdated
- Remove useVisibleTask$ example (simpler onClick$ approach is sufficient)
- Strengthen CSP security note wording per maintainer suggestion
- Remove redundant Complete Example for SSG section
- Update troubleshooting to reflect CSS-based icon visibility approach
@chindris-mihai-alexandru
Copy link
Copy Markdown
Contributor Author

Thanks @chindris-mihai-alexandru good additions and improvements overall. Can you address my comments before I click the merge button? 🤓

done ✅

@gioboa gioboa enabled auto-merge (squash) January 15, 2026 11:20
Copy link
Copy Markdown
Member

@maiieul maiieul left a comment

Choose a reason for hiding this comment

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

Thanks @chindris-mihai-alexandru good job!

@gioboa gioboa merged commit b9f600d into QwikDev:main Jan 15, 2026
15 checks passed
Copy link
Copy Markdown
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

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

Thanks @chindris-mihai-alexandru for your help 👏

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