-
Notifications
You must be signed in to change notification settings - Fork 4k
[Fix] Theme hashing #13173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] Theme hashing #13173
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
📈 Frontend coverage change detectedThe frontend unit test (vitest) coverage has increased by 0.0100%
✅ Coverage change is within normal range. |
There was a problem hiding this 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 fixes a critical bug where theme changes in nested configuration sections (like [theme.sidebar], [theme.light], [theme.dark]) were not triggering theme updates on app rerun. The previous implementation only hashed top-level theme properties, causing nested property changes to be silently ignored.
Key Changes:
- Introduced comprehensive recursive theme hashing via
sortThemeInputKeysutility that handles all nested objects and arrays - Simplified the App constructor to defer theme hash initialization until custom theme is received from server
- Added extensive test coverage for both the utility function and the hash change detection behavior
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
frontend/lib/src/theme/utils.ts |
Added sortThemeInputKeys utility function to recursively sort theme object keys for consistent hashing |
frontend/lib/src/theme/utils.test.ts |
Added comprehensive unit tests for sortThemeInputKeys covering nested objects, arrays, primitives, and edge cases |
frontend/lib/src/index.ts |
Exported the new sortThemeInputKeys utility for use in the app package |
frontend/app/src/App.tsx |
Updated createThemeHash to use recursive key sorting, removed premature hash calculation from constructor, removed unused toThemeInput import |
frontend/app/src/App.test.tsx |
Added extensive tests verifying hash change detection for all theme subsections (sidebar, light, dark) and nested configurations; updated existing test to better describe its behavior |
ea971ee to
9583ea1
Compare
|
@cursor review |
9583ea1 to
4d6ae66
Compare
4d6ae66 to
6b2b70e
Compare
SummaryThis PR fixes a bug in the theme hashing mechanism where changes to nested theme sections ( Key changes:
Code QualityStrengths
export function sortThemeInputKeys(obj: unknown): unknown {
if (obj === null || obj === undefined) {
return obj
}
// Handle arrays by recursively sorting their elements
if (Array.isArray(obj)) {
return obj.map(item => sortThemeInputKeys(item))
}
// Handle objects (including nested theme sections)
if (typeof obj === "object") {
const sorted: Record<string, unknown> = {}
Object.keys(obj)
.sort()
.forEach(key => {
sorted[key] = sortThemeInputKeys((obj as Record<string, unknown>)[key])
})
return sorted
}
// Return primitives as-is
return obj
}
// Initialize themeHash to empty string to ensure the first processThemeInput
// call always processes the theme (whether null or custom theme from server).
// This prevents the bug where a cached custom theme isn't cleared when the
// server sends null, because null and undefined both hash to the same value.
themeHash: "",
Minor Observations
Test CoverageUnit Tests (Excellent)The test coverage is comprehensive and follows TypeScript testing best practices:
E2E TestsNo new E2E tests were added. Given that this is primarily a bug fix for an internal hashing mechanism, the existing theme E2E tests should continue to work. However, adding an E2E test that specifically validates theme subsection changes trigger proper reprocessing could be beneficial for regression prevention. Suggestion (optional): Consider adding an E2E test that:
Backwards Compatibility✅ Fully backwards compatible
Security & RiskSecurity✅ No security concerns identified
Risk AssessmentLow risk - This is a targeted bug fix with:
Potential edge case to consider: The
This behavior is acceptable for theme configurations, which should only contain JSON-serializable values. RecommendationsNo blocking issues identified. The PR is well-implemented with good test coverage. Optional improvements (non-blocking):
VerdictAPPROVED: This is a well-implemented bug fix with comprehensive unit test coverage. The changes are targeted, backwards compatible, and pose minimal risk. The new This is an automated AI review. Please verify the feedback and use your judgment. |
lukasmasuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Our current theme hashing only handles top level `[theme]` properties in calculating the theme hash to determine whether theme has been updated. This was sufficient prior to custom theming, but now section theme changes are silently ignored and a re-run does not trigger the expected update. This PR implements comprehensive theme hashing that includes all theme properties - including new subsections (`light`, `dark`, etc.) so changes now properly trigger theme reprocessing.
Describe your changes
Our current theme hashing only handles top level
[theme]properties in calculating the theme hash to determine whether theme has been updated. This was sufficient prior to custom theming, but now section theme changes are silently ignored and a re-run does not trigger the expected update.Issue Repro:
[theme.sidebar]section of yourconfig.toml- setprimaryColor = "blue"primaryColor = "green"This PR implements comprehensive theme hashing that includes all theme properties - including new subsections (
light,dark, etc.) so changes now properly trigger theme reprocessing.Testing Plan