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
perf: move getDirtyValues util to avoid additional module perload (#8877)
Myles Scolnick9eafdbb55830
diff --git a/frontend/src/components/app-config/__tests__/get-dirty-values.test.ts b/frontend/src/components/app-config/__tests__/get-dirty-values.test.tsindex f1443282f7..ac8a0f5a13 100644--- a/frontend/src/components/app-config/__tests__/get-dirty-values.test.ts+++ b/frontend/src/components/app-config/__tests__/get-dirty-values.test.ts@@ -2,7 +2,7 @@import { describe, expect, test } from "vitest";import type { UserConfig } from "@/core/config/config-schema";-import { applyManualInjections, getDirtyValues } from "../user-config-form";+import { applyManualInjections, getDirtyValues } from "../get-dirty-values";describe("getDirtyValues", () => {test("extracts only dirty fields", () => {diff --git a/frontend/src/components/app-config/get-dirty-values.ts b/frontend/src/components/app-config/get-dirty-values.tsnew file mode 100644index 0000000000..fd6544decd--- /dev/null+++ b/frontend/src/components/app-config/get-dirty-values.ts@@ -0,0 +1,100 @@+/* Copyright 2026 Marimo. All rights reserved. */++import type { FieldPath, FieldValues } from "react-hook-form";+import type { UserConfig } from "@/core/config/config-schema";++/**+ * Extract only the values that have been modified (dirty) from form state.+ * This prevents sending unchanged fields that could overwrite backend values.+ */+export function getDirtyValues<T extends FieldValues>(+ values: T,+ dirtyFields: Partial<Record<keyof T, unknown>>,+): Partial<T> {+ const result: Partial<T> = {};+ for (const key of Object.keys(dirtyFields) as (keyof T)[]) {+ const dirty = dirtyFields[key];+ const value = values[key];++ // Skip if the value no longer exists (e.g., deleted from a record)+ if (value === undefined) {+ continue;+ }++ if (dirty === true) {+ result[key] = value;+ } else if (typeof dirty === "object" && dirty !== null) {+ // Nested object - recurse+ const nested = getDirtyValues(+ value as FieldValues,+ dirty as Partial<Record<string, unknown>>,+ );+ if (Object.keys(nested).length > 0) {+ result[key] = nested as T[keyof T];+ }+ }+ }+ return result;+}++type ManualInjector = (+ values: UserConfig,+ dirtyValues: Partial<UserConfig>,+) => void;++const modelsAiInjection = (+ values: UserConfig,+ dirtyValues: Partial<UserConfig>,+) => {+ dirtyValues.ai = {+ ...dirtyValues.ai,+ models: {+ ...dirtyValues.ai?.models,+ displayed_models: values.ai?.models?.displayed_models ?? [],+ custom_models: values.ai?.models?.custom_models ?? [],+ },+ };+};++// Some fields (like AI model lists) have empty arrays as default values.+// If a user explicitly clears them, RHF won't mark them dirty, so we use+// touchedFields to force-include those values in the payload.+const MANUAL_INJECT_ENTRIES = [+ ["ai.models.displayed_models", modelsAiInjection],+ ["ai.models.custom_models", modelsAiInjection],+] as const satisfies readonly (readonly [+ FieldPath<UserConfig>,+ ManualInjector,+])[];++const MANUAL_INJECT_FIELDS = new Map(MANUAL_INJECT_ENTRIES);++const isTouchedPath = (+ touched: unknown,+ path: FieldPath<UserConfig>,+): boolean => {+ if (!touched) {+ return false;+ }+ let current: unknown = touched;+ for (const segment of path.split(".")) {+ if (typeof current !== "object" || current === null) {+ return false;+ }+ current = (current as Record<string, unknown>)[segment];+ }+ return current === true;+};++export const applyManualInjections = (opts: {+ values: UserConfig;+ dirtyValues: Partial<UserConfig>;+ touchedFields: unknown;+}) => {+ const { values, dirtyValues, touchedFields } = opts;+ for (const [fieldPath, injector] of MANUAL_INJECT_FIELDS) {+ if (isTouchedPath(touchedFields, fieldPath)) {+ injector(values, dirtyValues);+ }+ }+};diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsxindex 1aad280e31..29db77abda 100644--- a/frontend/src/components/app-config/user-config-form.tsx+++ b/frontend/src/components/app-config/user-config-form.tsx@@ -15,7 +15,6 @@ import {} from "lucide-react";import React, { useId, useRef } from "react";import { useLocale } from "react-aria";-import type { FieldPath, FieldValues } from "react-hook-form";import { useForm } from "react-hook-form";import type z from "zod";import { Button } from "@/components/ui/button";@@ -59,105 +58,10 @@ import { Tooltip } from "../ui/tooltip";import { AiConfig } from "./ai-config";import { formItemClasses, SettingGroup } from "./common";import { DataForm } from "./data-form";+import { applyManualInjections, getDirtyValues } from "./get-dirty-values";import { IsOverridden } from "./is-overridden";import { OptionalFeatures } from "./optional-features";-/**- * Extract only the values that have been modified (dirty) from form state.- * This prevents sending unchanged fields that could overwrite backend values.- */-export function getDirtyValues<T extends FieldValues>(- values: T,- dirtyFields: Partial<Record<keyof T, unknown>>,-): Partial<T> {- const result: Partial<T> = {};- for (const key of Object.keys(dirtyFields) as (keyof T)[]) {- const dirty = dirtyFields[key];- const value = values[key];-- // Skip if the value no longer exists (e.g., deleted from a record)- if (value === undefined) {- continue;- }-- if (dirty === true) {- result[key] = value;- } else if (typeof dirty === "object" && dirty !== null) {- // Nested object - recurse- const nested = getDirtyValues(- value as FieldValues,- dirty as Partial<Record<string, unknown>>,- );- if (Object.keys(nested).length > 0) {- result[key] = nested as T[keyof T];- }- }- }- return result;-}--type ManualInjector = (- values: UserConfig,- dirtyValues: Partial<UserConfig>,-) => void;--const modelsAiInjection = (- values: UserConfig,- dirtyValues: Partial<UserConfig>,-) => {- dirtyValues.ai = {- ...dirtyValues.ai,- models: {- ...dirtyValues.ai?.models,- displayed_models: values.ai?.models?.displayed_models ?? [],- custom_models: values.ai?.models?.custom_models ?? [],- },- };-};--// Some fields (like AI model lists) have empty arrays as default values.-// If a user explicitly clears them, RHF won't mark them dirty, so we use-// touchedFields to force-include those values in the payload.-const MANUAL_INJECT_ENTRIES = [- ["ai.models.displayed_models", modelsAiInjection],- ["ai.models.custom_models", modelsAiInjection],-] as const satisfies readonly (readonly [- FieldPath<UserConfig>,- ManualInjector,-])[];--const MANUAL_INJECT_FIELDS = new Map(MANUAL_INJECT_ENTRIES);--const isTouchedPath = (- touched: unknown,- path: FieldPath<UserConfig>,-): boolean => {- if (!touched) {- return false;- }- let current: unknown = touched;- for (const segment of path.split(".")) {- if (typeof current !== "object" || current === null) {- return false;- }- current = (current as Record<string, unknown>)[segment];- }- return current === true;-};--export const applyManualInjections = (opts: {- values: UserConfig;- dirtyValues: Partial<UserConfig>;- touchedFields: unknown;-}) => {- const { values, dirtyValues, touchedFields } = opts;- for (const [fieldPath, injector] of MANUAL_INJECT_FIELDS) {- if (isTouchedPath(touchedFields, fieldPath)) {- injector(values, dirtyValues);- }- }-};-const categories = [{id: "editor",diff --git a/frontend/src/components/editor/package-alert.tsx b/frontend/src/components/editor/package-alert.tsxindex 35f3e1bece..84a4bd49ec 100644--- a/frontend/src/components/editor/package-alert.tsx+++ b/frontend/src/components/editor/package-alert.tsx@@ -44,7 +44,7 @@ import {type UserConfig,UserConfigSchema,} from "../../core/config/config-schema";-import { getDirtyValues } from "../app-config/user-config-form";+import { getDirtyValues } from "../app-config/get-dirty-values";import { Button } from "../ui/button";import {DropdownMenu,diff --git a/frontend/src/plugins/impl/chat/ChatPlugin.tsx b/frontend/src/plugins/impl/chat/ChatPlugin.tsxindex c98ff3d7e0..993b7c9284 100644--- a/frontend/src/plugins/impl/chat/ChatPlugin.tsx+++ b/frontend/src/plugins/impl/chat/ChatPlugin.tsx@@ -1,15 +1,18 @@/* Copyright 2026 Marimo. All rights reserved. */import type { UIMessage } from "ai";-import { Suspense } from "react";+import React, { Suspense } from "react";import { z } from "zod";import { TooltipProvider } from "@/components/ui/tooltip";import { createPlugin } from "@/plugins/core/builder";import { rpc } from "@/plugins/core/rpc";import { Arrays } from "@/utils/arrays";-import { Chatbot } from "./chat-ui";import type { SendMessageRequest } from "./types";+const LazyChatbot = React.lazy(() =>+ import("./chat-ui").then((m) => ({ default: m.Chatbot })),+);+// eslint-disable-next-line @typescript-eslint/consistent-type-definitionsexport type PluginFunctions = {get_chat_history: (req: {}) => Promise<{ messages: UIMessage[] }>;@@ -72,7 +75,7 @@ export const ChatPlugin = createPlugin<{ messages: UIMessage[] }>(.renderer((props) => (<TooltipProvider><Suspense>- <Chatbot+ <LazyChatbotprompts={props.data.prompts}showConfigurationControls={props.data.showConfigurationControls}maxHeight={props.data.maxHeight}