Skip to content

feat(Utility): update getTheme return value#7874

Merged
ArgoZhang merged 3 commits intomainfrom
fix-theme
Apr 14, 2026
Merged

feat(Utility): update getTheme return value#7874
ArgoZhang merged 3 commits intomainfrom
fix-theme

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Apr 14, 2026

Link issues

fixes #7871

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Adjust utility helpers and theme retrieval behavior in the BootstrapBlazor front-end module.

New Features:

  • Allow getTheme to optionally ignore localStorage and read the theme only from the document attribute.

Enhancements:

  • Normalize JavaScript utility code style and remove inline comments and redundant JSDoc blocks for cleaner client-side utilities.

Copilot AI review requested due to automatic review settings April 14, 2026 03:40
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 14, 2026

Reviewer's Guide

Refactors utility helpers for DOM/script/link management and updates getTheme to optionally bypass localStorage and always resolve concrete theme values, while performing minor style cleanups.

File-Level Changes

Change Details Files
Update getTheme behavior to support optionally ignoring localStorage and to always resolve non-null, non-'auto' theme values via getAutoThemeValue.
  • Change getTheme signature to accept a useLocalstorage boolean parameter with a default of true.
  • When useLocalstorage is true, read theme from localStorage; otherwise read from data-bs-theme on documentElement.
  • If the resolved theme is null or 'auto', compute the theme via getAutoThemeValue() before returning.
  • Ensure getTheme always returns a concrete theme string rather than null or 'auto'.
src/BootstrapBlazor/wwwroot/modules/utility.js
Code style and minor refactors in utility helpers to standardize function expressions and remove inline comments/JSDoc that duplicated behavior.
  • Normalize anonymous function syntax by removing spaces before parentheses in various callbacks and function expressions (e.g., filter, debounce, hackTooltip, register/dispose).
  • Remove redundant or non-essential comments and JSDoc blocks around helper functions like addScript, addLink, autoAdd/autoRemove, debounce, getElement, and transition utilities.
  • Keep overall logic of utilities (script/link insertion/removal, debounce, visibility checks, tooltip hack, etc.) unchanged.
src/BootstrapBlazor/wwwroot/modules/utility.js

Assessment against linked issues

Issue Objective Addressed Explanation
#7871 Ensure DockViewV2 (and DockView) correctly apply the effective dark/light theme on the initial render, including when the site theme is set to Auto and the browser is in dark mode, by respecting the component Theme parameter.

Possibly linked issues

  • #N/A: PR fixes getTheme resolution, likely correcting DockView’s incorrect theme handling that breaks dark mode appearance.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added the bug Something isn't working label Apr 14, 2026
@bb-auto bb-auto bot added this to the v10.5.0 milestone Apr 14, 2026
@ArgoZhang ArgoZhang merged commit 75eb619 into main Apr 14, 2026
5 checks passed
@ArgoZhang ArgoZhang deleted the fix-theme branch April 14, 2026 03:40
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In getTheme, the useLocalstorage parameter is already defaulted to true, so the line useLocalstorage = useLocalstorage ?? true; is redundant and can be removed to avoid unnecessary reassignment of the parameter.
  • The updated getTheme now maps a stored or DOM theme value of 'auto' to getAutoThemeValue() instead of returning 'auto' as before; if some callers still need the raw 'auto' value, consider either documenting this behavioral change clearly or adding an option to return the original value.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `getTheme`, the `useLocalstorage` parameter is already defaulted to `true`, so the line `useLocalstorage = useLocalstorage ?? true;` is redundant and can be removed to avoid unnecessary reassignment of the parameter.
- The updated `getTheme` now maps a stored or DOM `theme` value of `'auto'` to `getAutoThemeValue()` instead of returning `'auto'` as before; if some callers still need the raw `'auto'` value, consider either documenting this behavioral change clearly or adding an option to return the original value.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a06b36f) to head (df564d1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7874   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          764       764           
  Lines        34162     34162           
  Branches      4703      4703           
=========================================
  Hits         34162     34162           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Updates the JavaScript theme utility to change what getTheme() returns, intended to address theme initialization issues (linked to #7871) and bumps the package version.

Changes:

  • Modify getTheme() in utility.js (new parameter + new resolution behavior for 'auto').
  • Minor JS formatting/comment cleanup in utility.js.
  • Bump BootstrapBlazor package version to 10.5.1-beta08.

Reviewed changes

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

File Description
src/BootstrapBlazor/wwwroot/modules/utility.js Changes getTheme() behavior/signature and applies minor JS formatting/comment removals.
src/BootstrapBlazor/BootstrapBlazor.csproj Version bump to 10.5.1-beta08.

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

Comment on lines +660 to +673
export function getTheme(useLocalstorage = true) {
useLocalstorage = useLocalstorage ?? true;
let theme = null;
if (useLocalstorage) {
theme = localStorage.getItem('theme');
}
else {
theme = document.documentElement.getAttribute('data-bs-theme');
}

if (theme === null || theme === 'auto') {
theme = getAutoThemeValue();
}
return theme;
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

getTheme() now resolves a stored/attribute value of 'auto' into 'dark'/'light'. However ThemeProvider.razor.js calls getTheme() when ThemeValue === 'useLocalStorage' and then immediately calls setTheme(currentTheme, true) (which persists back to localStorage). With this change, a previously saved 'auto' preference will be overwritten as 'dark' or 'light', breaking future auto-switching on prefers-color-scheme changes.

Also, when useLocalstorage is true and localStorage has no value (or an empty string), the function no longer falls back to data-bs-theme like the previous implementation did.

Consider keeping getTheme() returning the persisted theme value ('auto'|'dark'|'light'|null) and adding an explicit option/new API to return the effective theme (resolving 'auto' via getAutoThemeValue()), then update only the consumers that need the effective theme.

Copilot uses AI. Check for mistakes.
Comment on lines +660 to +663
export function getTheme(useLocalstorage = true) {
useLocalstorage = useLocalstorage ?? true;
let theme = null;
if (useLocalstorage) {
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

Parameter name useLocalstorage is inconsistent with the established localStorage casing (and with the existing useLocalStorage string used by ThemeValue.UseLocalStorage). Renaming it to useLocalStorage would improve readability and reduce confusion when this exported API is used directly from JS.

Suggested change
export function getTheme(useLocalstorage = true) {
useLocalstorage = useLocalstorage ?? true;
let theme = null;
if (useLocalstorage) {
export function getTheme(useLocalStorage = true) {
useLocalStorage = useLocalStorage ?? true;
let theme = null;
if (useLocalStorage) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(DockViewV2): dark/light theme is not applied on initial rendering

2 participants