fix: sync language at render time without notifying subscribers
setLanguage() during App's render fired onLanguageChange, which made the same component's useSyncExternalStore schedule an update mid-render (React: cannot update a component while rendering a different component). syncLanguage() updates the module silently; re-renders flow through the settings store, which is the only path a renderer language change takes.
This commit is contained in:
1 parent
1054c2a661
commit
806fd93638
2 files changed
+16
-6
No files matched your search
@@ -70,6 +70,15 @@ export function setLanguage(lang: Language): void {
|
||||
for (const listener of listeners) listener(lang)
|
||||
}
|
||||
|
||||
/** Render-time sync for the React tree: update the module language WITHOUT
|
||||
* notifying subscribers — firing listeners during another component's render
|
||||
* makes React warn ("cannot update a component while rendering a different
|
||||
* component"). Renderer components re-render via the settings store instead;
|
||||
* the notifying setLanguage stays for the main process (tray rebuild). */
|
||||
export function syncLanguage(lang: Language): void {
|
||||
current = lang
|
||||
}
|
||||
|
||||
export function getLanguage(): Language {
|
||||
return current
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user