Skip to content

Commit c519c0a

Browse files
SuperMarioYLclaude
andcommitted
release: v0.0.24 — memoize Auth/Theme context values
AuthProvider and ThemeProvider memoize their context value with useMemo instead of allocating a new object each render, avoiding cascading consumer re-renders (incl. the antd ConfigProvider subtree). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3af14a4 commit c519c0a

5 files changed

Lines changed: 21 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to the Bison project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.0.24] - 2026-06-19
9+
10+
### Changed — Frontend re-render reduction
11+
12+
- `AuthProvider` and `ThemeProvider` now memoize their context value (`useMemo`) instead of allocating a fresh object every render, so consumers (and, for the theme, the whole Ant Design `ConfigProvider` subtree) no longer re-render on unrelated parent renders.
13+
814
## [0.0.23] - 2026-06-19
915

1016
### Changed — Centralized frontend error handling

deploy/charts/bison/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ apiVersion: v2
22
name: bison
33
description: Bison - GPU 资源计费平台,基于 Capsule 多租户 + OpenCost 成本追踪
44
type: application
5-
version: 0.0.23
6-
appVersion: "0.0.23"
5+
version: 0.0.24
6+
appVersion: "0.0.24"
77
keywords:
88
- gpu
99
- billing

web-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bison-web-ui",
3-
"version": "0.0.23",
3+
"version": "0.0.24",
44
"private": true,
55
"scripts": {
66
"dev": "vite",

web-ui/src/contexts/AuthContext.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
1+
import React, { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react';
22
import { getAuthStatus } from '../services/api';
33

44
interface AuthContextType {
@@ -72,18 +72,12 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
7272
setUsername(null);
7373
}, []);
7474

75-
return (
76-
<AuthContext.Provider value={{
77-
isAuthenticated,
78-
authEnabled,
79-
username,
80-
loading,
81-
logout,
82-
checkAuth
83-
}}>
84-
{children}
85-
</AuthContext.Provider>
75+
const value = useMemo<AuthContextType>(
76+
() => ({ isAuthenticated, authEnabled, username, loading, logout, checkAuth }),
77+
[isAuthenticated, authEnabled, username, loading, logout, checkAuth],
8678
);
79+
80+
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
8781
};
8882

8983
export const useAuth = () => {

web-ui/src/contexts/ThemeContext.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { createContext, useContext, useState, useEffect, useCallback } from 'react';
1+
import React, { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react';
22

33
type ThemeMode = 'light' | 'dark';
44

@@ -56,16 +56,12 @@ export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ childre
5656
setThemeState(newTheme);
5757
}, []);
5858

59-
return (
60-
<ThemeContext.Provider value={{
61-
theme,
62-
toggleTheme,
63-
setTheme,
64-
isDark: theme === 'dark'
65-
}}>
66-
{children}
67-
</ThemeContext.Provider>
59+
const value = useMemo<ThemeContextType>(
60+
() => ({ theme, toggleTheme, setTheme, isDark: theme === 'dark' }),
61+
[theme, toggleTheme, setTheme],
6862
);
63+
64+
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
6965
};
7066

7167
export const useTheme = (): ThemeContextType => {

0 commit comments

Comments
 (0)