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
chore: enable React immutability lint (#10884)
Shahmir Varqha5d5ea3f01652
diff --git a/frontend/.oxlintrc.json b/frontend/.oxlintrc.jsonindex d9f131141a..83f2f769bc 100644--- a/frontend/.oxlintrc.json+++ b/frontend/.oxlintrc.json@@ -58,7 +58,6 @@"no-underscore-dangle": "off","react/exhaustive-effect-dependencies": "off","react/forbid-component-props": "off",- "react/immutability": "off","react/incompatible-library": "off","react/jsx-no-literals": "off","react/no-unstable-nested-components": ["error", { "allowAsProps": true }],diff --git a/frontend/src/components/editor/__tests__/dynamic-favicon.test.tsx b/frontend/src/components/editor/__tests__/dynamic-favicon.test.tsxindex 805b1239d7..244b02be10 100644--- a/frontend/src/components/editor/__tests__/dynamic-favicon.test.tsx+++ b/frontend/src/components/editor/__tests__/dynamic-favicon.test.tsx@@ -1,6 +1,6 @@/* Copyright 2026 Marimo. All rights reserved. */-import { render } from "@testing-library/react";+import { render, waitFor } from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { useCellErrors } from "@/core/cells/cells";import { DynamicFavicon } from "../dynamic-favicon";@@ -14,6 +14,10 @@ describe("DynamicFavicon", () => {let favicon: HTMLLinkElement;beforeEach(() => {+ document+ .querySelectorAll("link[rel~='icon']")+ .forEach((element) => element.remove());+// Mock favicon elementfavicon = document.createElement("link");favicon.rel = "icon";@@ -28,7 +32,9 @@ describe("DynamicFavicon", () => {});afterEach(() => {- favicon.remove();+ document+ .querySelectorAll("link[rel~='icon']")+ .forEach((element) => element.remove());vi.clearAllMocks();vi.useRealTimers();});@@ -113,6 +119,34 @@ describe("DynamicFavicon", () => {expect(newFavicon).not.toBeNull();});+ it("recreates a removed favicon when the window regains focus", async () => {+ render(<DynamicFavicon isRunning={false} />);+ favicon.remove();++ window.dispatchEvent(new Event("focus"));++ await waitFor(() => {+ const currentFavicon =+ document.querySelector<HTMLLinkElement>("link[rel~='icon']");+ expect(currentFavicon?.href.endsWith("favicon.ico")).toBe(true);+ });+ });++ it("resets the current favicon after the link is replaced", async () => {+ render(<DynamicFavicon isRunning={false} />);+ const replacement = document.createElement("link");+ replacement.rel = "icon";+ replacement.href = "./replacement.ico";+ favicon.replaceWith(replacement);++ window.dispatchEvent(new Event("focus"));++ await waitFor(() => {+ expect(replacement.href.endsWith("favicon.ico")).toBe(true);+ expect(document.querySelector("link[rel~='icon']")).toBe(replacement);+ });+ });+describe("notifications", () => {beforeEach(() => {vi.spyOn(document, "visibilityState", "get").mockReturnValue("hidden");diff --git a/frontend/src/components/editor/cell/code/__tests__/rtc-editor-config.test.ts b/frontend/src/components/editor/cell/code/__tests__/rtc-editor-config.test.tsnew file mode 100644index 0000000000..e9b8bacb70--- /dev/null+++ b/frontend/src/components/editor/cell/code/__tests__/rtc-editor-config.test.ts@@ -0,0 +1,50 @@+/* Copyright 2026 Marimo. All rights reserved. */++import { EditorState } from "@codemirror/state";+import { describe, expect, it } from "vitest";+import { composeRtcEditorConfig } from "../cell-editor";++describe("composeRtcEditorConfig", () => {+ it("does not accumulate RTC extensions across reconfigurations", () => {+ const baseExtension = EditorState.readOnly.of(false);+ const baseExtensions = [baseExtension];+ const firstRtc = {+ code: "first RTC code",+ extension: EditorState.tabSize.of(2),+ };+ const secondRtc = {+ code: "second RTC code",+ extension: EditorState.tabSize.of(4),+ };++ const firstConfig = composeRtcEditorConfig(+ "local code",+ baseExtensions,+ firstRtc,+ );+ const secondConfig = composeRtcEditorConfig(+ "local code",+ baseExtensions,+ secondRtc,+ );++ expect(baseExtensions).toEqual([baseExtension]);+ expect(firstConfig).toEqual({+ code: firstRtc.code,+ extensions: [baseExtension, firstRtc.extension],+ });+ expect(secondConfig).toEqual({+ code: secondRtc.code,+ extensions: [baseExtension, secondRtc.extension],+ });+ });++ it("reuses the base configuration when RTC is disabled", () => {+ const extensions = [EditorState.readOnly.of(false)];++ const config = composeRtcEditorConfig("local code", extensions, undefined);++ expect(config).toEqual({ code: "local code", extensions });+ expect(config.extensions).toBe(extensions);+ });+});diff --git a/frontend/src/components/editor/cell/code/cell-editor.tsx b/frontend/src/components/editor/cell/code/cell-editor.tsxindex ff6187b641..b7c7676e76 100644--- a/frontend/src/components/editor/cell/code/cell-editor.tsx+++ b/frontend/src/components/editor/cell/code/cell-editor.tsx@@ -1,6 +1,6 @@/* Copyright 2026 Marimo. All rights reserved. */import { historyField } from "@codemirror/commands";-import { EditorState, StateEffect } from "@codemirror/state";+import { EditorState, type Extension, StateEffect } from "@codemirror/state";import { EditorView, ViewPlugin } from "@codemirror/view";import { useIntersectionObserver } from "@uidotdev/usehooks";import { useAtom, useAtomValue } from "jotai";@@ -95,6 +95,21 @@ export interface CellEditorPropstooltipParentSelector?: string;}+export function composeRtcEditorConfig(+ code: string,+ extensions: Extension[],+ rtc: ReturnType<typeof realTimeCollaboration> | undefined,+): { code: string; extensions: Extension[] } {+ if (!rtc) {+ return { code, extensions };+ }++ return {+ code: rtc.code,+ extensions: [...extensions, rtc.extension],+ };+}+const CellEditorInternal = ({theme,showPlaceholder,@@ -343,27 +358,31 @@ const CellEditorInternal = ({]);const rtcEnabled = isRtcEnabled() && canUseRtc(cellId);- const handleInitializeEditor = useEvent(() => {- // If rtc is enabled, use collaborative editing- if (rtcEnabled) {- const rtc = realTimeCollaboration(- cellId,- (code) => {- // It's not really a formatting change,- // but this means it won't be marked as stale- cellActions.updateCellCode({ cellId, code, formattingChange: true });- },- code,- );- extensions.push(rtc.extension);- code = rtc.code;+ const createEditorConfig = (initialCode?: string) => {+ if (!rtcEnabled) {+ return composeRtcEditorConfig(code, extensions, undefined);}+ const rtc = realTimeCollaboration(+ cellId,+ (code) => {+ // It's not really a formatting change,+ // but this means it won't be marked as stale+ cellActions.updateCellCode({ cellId, code, formattingChange: true });+ },+ initialCode,+ );+ return composeRtcEditorConfig(code, extensions, rtc);+ };++ const handleInitializeEditor = useEvent(() => {+ const editorConfig = createEditorConfig(code);+// Create a new editorconst ev = new EditorView({state: EditorState.create({- doc: code,- extensions: extensions,+ doc: editorConfig.code,+ extensions: editorConfig.extensions,}),});setEditorView(ev);@@ -377,19 +396,11 @@ const CellEditorInternal = ({const handleReconfigureEditor = useEvent(() => {invariant(editorViewRef.current !== null, "Editor view is not initialized");- // If rtc is enabled, use collaborative editing- if (rtcEnabled) {- const rtc = realTimeCollaboration(cellId, (code) => {- // It's not really a formatting change,- // but this means it won't be marked as stale- cellActions.updateCellCode({ cellId, code, formattingChange: true });- });- extensions.push(rtc.extension);- }+ const editorConfig = createEditorConfig();editorViewRef.current.dispatch({effects: [- StateEffect.reconfigure.of([extensions]),+ StateEffect.reconfigure.of([editorConfig.extensions]),reconfigureLanguageEffect(editorViewRef.current, {completionConfig: userConfig.completion,hotkeysProvider: new OverridingHotkeyProvider(@@ -406,26 +417,14 @@ const CellEditorInternal = ({const handleDeserializeEditor = useEvent(() => {invariant(serializedEditorState, "Editor view is not initialized");- if (rtcEnabled) {- const rtc = realTimeCollaboration(- cellId,- (code) => {- // It's not really a formatting change,- // but this means it won't be marked as stale- cellActions.updateCellCode({ cellId, code, formattingChange: true });- },- code,- );- extensions.push(rtc.extension);- code = rtc.code;- }+ const editorConfig = createEditorConfig(code);const ev = new EditorView({state: EditorState.fromJSON(serializedEditorState,{- doc: code,- extensions: extensions,+ doc: editorConfig.code,+ extensions: editorConfig.extensions,},{ history: historyField },),diff --git a/frontend/src/components/editor/dynamic-favicon.tsx b/frontend/src/components/editor/dynamic-favicon.tsxindex 36c395a96e..eac30e148e 100644--- a/frontend/src/components/editor/dynamic-favicon.tsx+++ b/frontend/src/components/editor/dynamic-favicon.tsx@@ -22,6 +22,19 @@ async function getFaviconUrl(key: FaviconKey): Promise<string> {return FAVICON_PATHS[key];}+function getOrCreateFavicon(): HTMLLinkElement {+ const existingFavicon =+ document.querySelector<HTMLLinkElement>("link[rel~='icon']");+ if (existingFavicon) {+ return existingFavicon;+ }++ const favicon = document.createElement("link");+ favicon.rel = "icon";+ document.head.append(favicon);+ return favicon;+}+interface Props {isRunning: boolean;}@@ -64,16 +77,9 @@ export const DynamicFavicon = (props: Props) => {const { isRunning } = props;const errors = useCellErrors();- let favicon: HTMLLinkElement | null =- document.querySelector("link[rel~='icon']");-- if (!favicon) {- favicon = document.createElement("link");- favicon.rel = "icon";- document.getElementsByTagName("head")[0].append(favicon);- }-useEffect(() => {+ const favicon = getOrCreateFavicon();+// No change on startup (autorun enabled or not)// Treat the default marimo favicon as "idle"if (!isRunning && favicon.href.includes("favicon")) {@@ -105,7 +111,7 @@ export const DynamicFavicon = (props: Props) => {};updateFavicon();- }, [isRunning, errors, favicon]);+ }, [isRunning, errors]);// Send user notification when run has completedconst prevRunning = usePrevious(isRunning) ?? isRunning;@@ -118,6 +124,7 @@ export const DynamicFavicon = (props: Props) => {// When notebook comes back in focus, reset faviconuseEventListener(window, "focus", async (_) => {if (!isRunning) {+ const favicon = getOrCreateFavicon();favicon.href = await getFaviconUrl("idle");}});diff --git a/frontend/src/plugins/impl/data-editor/__tests__/glide-data-editor.test.tsx b/frontend/src/plugins/impl/data-editor/__tests__/glide-data-editor.test.tsxindex ab35c156e6..bccf81a839 100644--- a/frontend/src/plugins/impl/data-editor/__tests__/glide-data-editor.test.tsx+++ b/frontend/src/plugins/impl/data-editor/__tests__/glide-data-editor.test.tsx@@ -6,31 +6,36 @@ import { beforeEach, describe, expect, it, vi } from "vitest";import { TooltipProvider } from "@/components/ui/tooltip";import { GlideDataEditor } from "../glide-data-editor";-const capturedDataEditor = vi.hoisted(() => ({- ref: undefined as React.RefObject<HTMLElement> | undefined,- onCellEdited: undefined as- | ((cell: [number, number], value: { data: unknown }) => void)- | undefined,- onRowAppended: undefined as (() => void) | undefined,-}));+interface MockDataEditorProps {+ portalElementRef?: React.RefObject<HTMLElement>;+ onCellEdited?: (cell: [number, number], value: { data: unknown }) => void;+ onRowAppended?: () => void;+}++const captureDataEditorProps = vi.hoisted(() =>+ vi.fn<(props: MockDataEditorProps) => void>(),+);++const capturedDataEditor = {+ get ref() {+ return captureDataEditorProps.mock.lastCall?.[0].portalElementRef;+ },+ get onCellEdited() {+ return captureDataEditorProps.mock.lastCall?.[0].onCellEdited;+ },+ get onRowAppended() {+ return captureDataEditorProps.mock.lastCall?.[0].onRowAppended;+ },+};vi.mock("@glideapps/glide-data-grid", async () => {const React = await import("react");return {default: React.forwardRef(function MockDataEditor(- props: {- portalElementRef?: React.RefObject<HTMLElement>;- onCellEdited?: (- cell: [number, number],- value: { data: unknown },- ) => void;- onRowAppended?: () => void;- },+ props: MockDataEditorProps,_ref: React.Ref<HTMLDivElement>,) {- capturedDataEditor.ref = props.portalElementRef;- capturedDataEditor.onCellEdited = props.onCellEdited;- capturedDataEditor.onRowAppended = props.onRowAppended;+ captureDataEditorProps(props);return <div data-testid="mock-data-editor" />;}),CompactSelection: {