A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: set only partial updates for config changes (#7634)
Myles Scolnick1e6247509aeb
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsxindex ea734f879d..a8f08291cd 100644--- a/frontend/src/components/app-config/user-config-form.tsx+++ b/frontend/src/components/app-config/user-config-form.tsx@@ -182,7 +182,7 @@ export const UserConfigForm: React.FC = () => {}await saveUserConfig({ config: dirtyValues }).then(() => {// Update local state with form values- setConfig({ ...config, ...values });+ setConfig((prev) => ({ ...prev, ...values }));});};const onSubmit = useDebouncedCallback(onSubmitNotDebounced, FORM_DEBOUNCE);diff --git a/frontend/src/components/editor/actions/useConfigActions.tsx b/frontend/src/components/editor/actions/useConfigActions.tsxindex 348487279b..fd3892bba6 100644--- a/frontend/src/components/editor/actions/useConfigActions.tsx+++ b/frontend/src/components/editor/actions/useConfigActions.tsx@@ -11,9 +11,9 @@ export function useConfigActions() {const [appConfig, setAppConfig] = useAppConfig();const { saveAppConfig, saveUserConfig } = useRequestClient();- const handleUserConfig = async (values: UserConfig) => {+ const handleUserConfig = async (values: Partial<UserConfig>) => {await saveUserConfig({ config: values }).then(() => {- setConfig(values);+ setConfig((prev) => ({ ...prev, ...values }));});};@@ -39,7 +39,6 @@ export function useConfigActions() {label: "Config > Set theme: dark",handle: () => {handleUserConfig({- ...config,display: {...config.display,theme: "dark",@@ -51,7 +50,6 @@ export function useConfigActions() {label: "Config > Set theme: light",handle: () => {handleUserConfig({- ...config,display: {...config.display,theme: "light",@@ -63,7 +61,6 @@ export function useConfigActions() {label: "Config > Set theme: system",handle: () => {handleUserConfig({- ...config,display: {...config.display,theme: "system",@@ -76,7 +73,6 @@ export function useConfigActions() {hidden: config.keymap.preset === "vim",handle: () => {handleUserConfig({- ...config,keymap: {...config.keymap,preset: "vim",@@ -90,7 +86,6 @@ export function useConfigActions() {hidden: config.keymap.preset === "default",handle: () => {handleUserConfig({- ...config,keymap: {...config.keymap,preset: "default",@@ -102,7 +97,6 @@ export function useConfigActions() {label: "Config > Disable GitHub Copilot",handle: () => {handleUserConfig({- ...config,completion: {...config.completion,copilot: false,@@ -115,7 +109,6 @@ export function useConfigActions() {label: "Config > Enable GitHub Copilot",handle: () => {handleUserConfig({- ...config,completion: {...config.completion,copilot: "github",@@ -129,7 +122,6 @@ export function useConfigActions() {hidden: !config.display.reference_highlighting,handle: () => {handleUserConfig({- ...config,display: {...config.display,reference_highlighting: false,@@ -142,7 +134,6 @@ export function useConfigActions() {hidden: config.display.reference_highlighting,handle: () => {handleUserConfig({- ...config,display: {...config.display,reference_highlighting: true,@@ -155,7 +146,6 @@ export function useConfigActions() {hidden: config.display.cell_output === "above",handle: () => {handleUserConfig({- ...config,display: {...config.display,cell_output: "above",@@ -168,7 +158,6 @@ export function useConfigActions() {hidden: config.display.cell_output === "below",handle: () => {handleUserConfig({- ...config,display: {...config.display,cell_output: "below",diff --git a/frontend/src/components/editor/chrome/wrapper/footer-items/runtime-settings.tsx b/frontend/src/components/editor/chrome/wrapper/footer-items/runtime-settings.tsxindex bdd9f591bd..b4928b84aa 100644--- a/frontend/src/components/editor/chrome/wrapper/footer-items/runtime-settings.tsx+++ b/frontend/src/components/editor/chrome/wrapper/footer-items/runtime-settings.tsx@@ -18,7 +18,7 @@ import {DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";import { Switch } from "@/components/ui/switch";-import { useResolvedMarimoConfig, useUserConfig } from "@/core/config/config";+import { useResolvedMarimoConfig } from "@/core/config/config";import { useRequestClient } from "@/core/network/requests";import { isWasm } from "@/core/wasm/utils";import { cn } from "@/utils/cn";@@ -32,8 +32,7 @@ export const RuntimeSettings: React.FC<RuntimeSettingsProps> = ({className,}) => {const { saveUserConfig } = useRequestClient();- const [userConfig, setUserConfig] = useUserConfig();- const config = useResolvedMarimoConfig()[0];+ const [config, setUserConfig] = useResolvedMarimoConfig();const [dropdownOpen, setDropdownOpen] = useState(false);// Close dropdown when screen size crosses the md breakpoint@@ -55,13 +54,13 @@ export const RuntimeSettings: React.FC<RuntimeSettingsProps> = ({// Send only the changed portion to avoid overwriting other config valuesawait saveUserConfig({config: { runtime: { auto_instantiate: checked } },- }).then(() =>+ }).then(() => {// Update local state with merged config- setUserConfig({- ...userConfig,- runtime: { ...userConfig.runtime, auto_instantiate: checked },- }),- );+ setUserConfig((prev) => ({+ ...prev,+ runtime: { ...prev.runtime, auto_instantiate: checked },+ }));+ });};const handleCellChangeToggle = async (checked: boolean) => {@@ -69,13 +68,13 @@ export const RuntimeSettings: React.FC<RuntimeSettingsProps> = ({// Send only the changed portion to avoid overwriting other config valuesawait saveUserConfig({config: { runtime: { on_cell_change: onCellChange } },- }).then(() =>+ }).then(() => {// Update local state with merged config- setUserConfig({- ...userConfig,- runtime: { ...userConfig.runtime, on_cell_change: onCellChange },- }),- );+ setUserConfig((prev) => ({+ ...prev,+ runtime: { ...prev.runtime, on_cell_change: onCellChange },+ }));+ });};const handleModuleReloadChange = async (@@ -84,13 +83,13 @@ export const RuntimeSettings: React.FC<RuntimeSettingsProps> = ({// Send only the changed portion to avoid overwriting other config valuesawait saveUserConfig({config: { runtime: { auto_reload: option } },- }).then(() =>+ }).then(() => {// Update local state with merged config- setUserConfig({- ...userConfig,- runtime: { ...userConfig.runtime, auto_reload: option },- }),- );+ setUserConfig((prev) => ({+ ...prev,+ runtime: { ...prev.runtime, auto_reload: option },+ }));+ });};// Check if all reactivity is disableddiff --git a/frontend/src/components/editor/controls/keyboard-shortcuts.tsx b/frontend/src/components/editor/controls/keyboard-shortcuts.tsxindex 4a5b360199..3cd7b88a64 100644--- a/frontend/src/components/editor/controls/keyboard-shortcuts.tsx+++ b/frontend/src/components/editor/controls/keyboard-shortcuts.tsx@@ -46,9 +46,9 @@ export const KeyboardShortcuts: React.FC = () => {useHotkey("global.showHelp", () => setIsOpen((v) => !v));- const saveConfigOptimistic = async (newConfig: UserConfig) => {+ const saveConfigOptimistic = async (newConfig: Partial<UserConfig>) => {const prevConfig = { ...config };- setConfig(newConfig);+ setConfig((prev) => ({ ...prev, ...newConfig }));await saveUserConfig({ config: newConfig }).catch((error) => {setConfig(prevConfig);throw error;@@ -62,7 +62,6 @@ export const KeyboardShortcuts: React.FC = () => {const shortcutString = shortcut.join("-");const newConfig = {- ...config,keymap: {...config.keymap,overrides: {@@ -83,7 +82,6 @@ export const KeyboardShortcuts: React.FC = () => {}const newConfig = {- ...config,keymap: {...config.keymap,overrides: {@@ -109,8 +107,7 @@ export const KeyboardShortcuts: React.FC = () => {return;}- const newConfig = {- ...config,+ const newConfig: Partial<UserConfig> = {keymap: {...config.keymap,overrides: {},diff --git a/frontend/src/components/editor/package-alert.tsx b/frontend/src/components/editor/package-alert.tsxindex 0310667452..9288cd98e4 100644--- a/frontend/src/components/editor/package-alert.tsx+++ b/frontend/src/components/editor/package-alert.tsx@@ -44,6 +44,7 @@ import {type UserConfig,UserConfigSchema,} from "../../core/config/config-schema";+import { getDirtyValues } from "../app-config/user-config-form";import { Button } from "../ui/button";import {DropdownMenu,@@ -370,8 +371,15 @@ const PackageManagerForm: React.FC = () => {});const onSubmit = async (values: UserConfig) => {- await saveUserConfig({ config: values }).then(() => {- setConfig(values);+ // Only send values that were actually changed to avoid+ // overwriting backend values the form doesn't manage+ const dirtyValues = getDirtyValues(values, form.formState.dirtyFields);+ if (Object.keys(dirtyValues).length === 0) {+ return; // Nothing changed+ }+ await saveUserConfig({ config: dirtyValues }).then(() => {+ // Update local state with form values+ setConfig((prev) => ({ ...prev, ...values }));});};diff --git a/frontend/src/core/ai/config.ts b/frontend/src/core/ai/config.tsindex f0b02ae56d..426fc995e3 100644--- a/frontend/src/core/ai/config.ts+++ b/frontend/src/core/ai/config.ts@@ -32,9 +32,9 @@ export const useModelChange = () => {const [userConfig, setUserConfig] = useAtom(userConfigAtom);const { saveUserConfig } = useRequestClient();- const saveConfig = async (newConfig: UserConfig) => {+ const saveConfig = async (newConfig: Partial<UserConfig>) => {await saveUserConfig({ config: newConfig }).then(() => {- setUserConfig(newConfig);+ setUserConfig((prev) => ({ ...prev, ...newConfig }));});};@@ -48,8 +48,7 @@ export const useModelChange = () => {return;}- const newConfig: UserConfig = {- ...userConfig,+ const newConfig: Partial<UserConfig> = {ai: {...userConfig.ai,models: {@@ -65,8 +64,7 @@ export const useModelChange = () => {};const saveModeChange = async (newMode: CopilotMode) => {- const newConfig: UserConfig = {- ...userConfig,+ const newConfig: Partial<UserConfig> = {ai: {...userConfig.ai,mode: newMode,diff --git a/frontend/src/core/config/feature-flag.tsx b/frontend/src/core/config/feature-flag.tsxindex 5ee5ba1204..797350fbde 100644--- a/frontend/src/core/config/feature-flag.tsx+++ b/frontend/src/core/config/feature-flag.tsx@@ -38,7 +38,7 @@ export function getFeatureFlag<T extends keyof ExperimentalFeatures>(function setFeatureFlag(feature: keyof ExperimentalFeatures, value: boolean) {// Send only the changed portion to avoid overwriting other config values- getRequestClient().saveUserConfig({+ void getRequestClient().saveUserConfig({config: { experimental: { [feature]: value } },});}