Skip to content

fix: prevent share pages from overriding the user's theme preference - #17098

Merged
wangq8 merged 1 commit into
infiniflow:mainfrom
euvre:fix/share-theme-override
Jul 20, 2026
Merged

wangq8 merged 1 commit into
infiniflow:mainfrom
euvre:fix/share-theme-override

Conversation

@euvre

@euvre euvre commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Visiting a shared chat/agent link (e.g. ?theme=light) called setTheme through useSyncThemeFromParams, and the ThemeProvider effect persisted every theme change to localStorage. As a result, a user in dark mode who opened a light-themed share page and then returned to the main app would see the app stuck in light mode after a browser refresh, because their stored preference had been silently overwritten.

This PR makes URL-driven theme sync non-destructive:

  • setTheme now accepts a persist flag (default true); when false, the theme is applied to the document but not written to localStorage.
  • useSyncThemeFromParams uses persist: false, so share pages render with the theme from the URL without touching the user's saved preference.
  • When leaving a share page, the theme active before entering is restored, so navigating back within the SPA immediately returns to the user's preferred mode without a refresh.

Manual theme toggles in the main app still persist as before.

Visiting a shared chat/agent link with ?theme=light persisted that theme
to localStorage, so the main app switched to light mode after refresh.
Theme synced from URL params is now applied without persistence, and the
previous theme is restored when leaving the share page.
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. 🧰 typescript Pull requests that update Typescript code labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f25a0a1-aef0-4a01-ad38-21b80a2bf708

📥 Commits

Reviewing files that changed from the base of the PR and between b2e88c9 and 69ff8dd.

📒 Files selected for processing (1)
  • web/src/components/theme-provider.tsx

📝 Walkthrough

Walkthrough

Theme updates now accept an optional persistence flag. Query-parameter theme changes avoid localStorage writes and restore the prior theme when the synchronization hook cleans up.

Changes

Theme persistence control

Layer / File(s) Summary
Provider persistence behavior
web/src/components/theme-provider.tsx
ThemeProvider adds optional persistence control, conditionally writes the selected theme to localStorage, and continues updating the document theme classes.
Query-parameter theme synchronization
web/src/components/theme-provider.tsx
useSyncThemeFromParams applies valid query themes without persistence and restores the original theme during cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant useSyncThemeFromParams
  participant ThemeProvider
  participant localStorage
  participant documentElement
  useSyncThemeFromParams->>ThemeProvider: setTheme(theme, false)
  ThemeProvider->>documentElement: update light/dark class
  ThemeProvider->>localStorage: write theme only when persistence is enabled
Loading

Suggested reviewers: jinhai-cn

Poem

A rabbit flips the theme at night,
Then leaves no footprint in storage’s light.
The old hue waits beneath the glow,
Restored when query breezes go.
Hop, hop—clean state in sight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Clear and specific; it matches the main change of making share-page theme sync non-destructive.
Description check ✅ Passed It includes the required Summary section and clearly explains the problem, fix, and resulting behavior changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@euvre euvre added the ci Continue Integration label Jul 20, 2026
@euvre
euvre requested a review from wangq8 July 20, 2026 07:34
@wangq8
wangq8 requested a review from dcc123456 July 20, 2026 07:40
@wangq8
wangq8 merged commit 67a2310 into infiniflow:main Jul 20, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files. 🧰 typescript Pull requests that update Typescript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants