fix: missing ExportMenuOptions in persist leads to useSelector re-render a lot (#4593)

* fix: missing ExportMenuOptions in persist leads to useSelector re-render

* chore: cleanup
This commit is contained in:
fullex 2025-04-09 13:54:15 +08:00 committed by GitHub
parent 24e28b86cf
commit 10efa444bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 17 additions and 45 deletions

View File

@ -70,20 +70,7 @@ const MessageMenubar: FC<Props> = (props) => {
const isUserMessage = message.role === 'user' const isUserMessage = message.role === 'user'
const exportMenuOptions = useSelector( const exportMenuOptions = useSelector((state: RootState) => state.settings.exportMenuOptions)
(state: RootState) =>
state.settings.exportMenuOptions || {
image: true,
markdown: true,
markdown_reason: true,
notion: true,
yuque: true,
joplin: true,
obsidian: true,
siyuan: true,
docx: true
}
)
const onCopy = useCallback( const onCopy = useCallback(
(e: React.MouseEvent) => { (e: React.MouseEvent) => {

View File

@ -156,20 +156,7 @@ const Topics: FC<Props> = ({ assistant: _assistant, activeTopic, setActiveTopic
[setActiveTopic] [setActiveTopic]
) )
const exportMenuOptions = useSelector( const exportMenuOptions = useSelector((state: RootState) => state.settings.exportMenuOptions)
(state: RootState) =>
state.settings.exportMenuOptions || {
image: true,
markdown: true,
markdown_reason: true,
notion: true,
yuque: true,
joplin: true,
obsidian: true,
siyuan: true,
docx: true
}
)
const getTopicMenuItems = useCallback( const getTopicMenuItems = useCallback(
(topic: Topic) => { (topic: Topic) => {

View File

@ -13,20 +13,7 @@ const ExportMenuOptions: FC = () => {
const { theme } = useTheme() const { theme } = useTheme()
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const exportMenuOptions = useSelector( const exportMenuOptions = useSelector((state: RootState) => state.settings.exportMenuOptions)
(state: RootState) =>
state.settings.exportMenuOptions || {
image: true,
markdown: true,
markdown_reason: true,
notion: true,
yuque: true,
joplin: true,
obsidian: true,
siyuan: true,
docx: true
}
)
const handleToggleOption = (option: string, checked: boolean) => { const handleToggleOption = (option: string, checked: boolean) => {
dispatch( dispatch(

View File

@ -42,7 +42,7 @@ const persistedReducer = persistReducer(
{ {
key: 'cherry-studio', key: 'cherry-studio',
storage, storage,
version: 92, version: 93,
blacklist: ['runtime', 'messages'], blacklist: ['runtime', 'messages'],
migrate migrate
}, },

View File

@ -13,7 +13,7 @@ import { createMigrate } from 'redux-persist'
import { RootState } from '.' import { RootState } from '.'
import { INITIAL_PROVIDERS, moveProvider } from './llm' import { INITIAL_PROVIDERS, moveProvider } from './llm'
import { mcpSlice } from './mcp' import { mcpSlice } from './mcp'
import { DEFAULT_SIDEBAR_ICONS } from './settings' import { DEFAULT_SIDEBAR_ICONS, initialState as settingsInitialState } from './settings'
// remove logo base64 data to reduce the size of the state // remove logo base64 data to reduce the size of the state
function removeMiniAppIconsFromState(state: RootState) { function removeMiniAppIconsFromState(state: RootState) {
@ -1173,6 +1173,17 @@ const migrateConfig = {
} catch (error) { } catch (error) {
return state return state
} }
},
'93': (state: RootState) => {
try {
if (!state?.settings?.exportMenuOptions) {
state.settings.exportMenuOptions = settingsInitialState.exportMenuOptions
return state
}
return state
} catch (error) {
return state
}
} }
} }

View File

@ -125,7 +125,7 @@ export interface SettingsState {
export type MultiModelMessageStyle = 'horizontal' | 'vertical' | 'fold' | 'grid' export type MultiModelMessageStyle = 'horizontal' | 'vertical' | 'fold' | 'grid'
const initialState: SettingsState = { export const initialState: SettingsState = {
showAssistants: true, showAssistants: true,
showTopics: true, showTopics: true,
sendMessageShortcut: 'Enter', sendMessageShortcut: 'Enter',