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
refactor: align React memo dependencies (#10820)
Shahmir Varqhab3212d07317b
diff --git a/frontend/.oxlintrc.json b/frontend/.oxlintrc.jsonindex 4fe747e99b..9a2574bc47 100644--- a/frontend/.oxlintrc.json+++ b/frontend/.oxlintrc.json@@ -62,7 +62,6 @@"react/immutability": "off","react/incompatible-library": "off","react/jsx-no-literals": "off",- "react/memo-dependencies": "off","react/no-deriving-state-in-effects": "off","react/no-unstable-nested-components": ["error", { "allowAsProps": true }],"react/preserve-manual-memoization": "off",diff --git a/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsx b/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsxindex c3b7752a62..ec918d6d32 100644--- a/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsx+++ b/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsx@@ -10,7 +10,7 @@ import {EyeIcon,EyeOffIcon,} from "lucide-react";-import { useMemo, useState } from "react";+import { useState } from "react";import { useLocale } from "react-aria";import {AddDataframeChart,@@ -98,11 +98,7 @@ export function ColumnExplorerPanel<TData>({hiddenColumns: hiddenColumnCount,} = getColumnCountForDisplay(table, totalColumns);const { visible: visibleColumnCount } = getUserColumnVisibilityCounts(table);- const columnVisibility = table.getState().columnVisibility;- const showOnlyColumnState = useMemo(- () => getShowOnlyColumnState(table),- [table, columnVisibility],- );+ const showOnlyColumnState = getShowOnlyColumnState(table);const { rowsAndColumns, hiddenSuffix } = prettifyRowColumnCount({numRows: totalRows,diff --git a/frontend/src/components/editor/chrome/components/feedback-button.tsx b/frontend/src/components/editor/chrome/components/feedback-button.tsxindex 0f3ff0ee7e..2818f2497f 100644--- a/frontend/src/components/editor/chrome/components/feedback-button.tsx+++ b/frontend/src/components/editor/chrome/components/feedback-button.tsx@@ -6,7 +6,7 @@ const Slot = SlotPrimitive.Slot;import { useAtomValue } from "jotai";import { ExternalLinkIcon, TriangleAlertIcon } from "lucide-react";-import React, { type PropsWithChildren, useMemo, useState } from "react";+import React, { type PropsWithChildren, useState } from "react";import { CopyClipboardIcon } from "@/components/icons/copy-icon";import { useImperativeModal } from "@/components/modal/ImperativeModal";import { Button } from "@/components/ui/button";@@ -94,8 +94,7 @@ export const FeedbackModal: React.FC<{);const notebook = useAtomValue(notebookAtom);- // biome-ignore lint/correctness/useExhaustiveDependencies: recompute when the notebook changes- const errors = useMemo(() => getCellErrorEntries(store), [notebook]);+ const errors = getCellErrorEntries(store);const cells = notebook.cellIds.inOrderIds.map((cellId) => notebook.cellData[cellId],@@ -145,10 +144,9 @@ export const FeedbackModal: React.FC<{return contents;}, [includeCode, notebookSourceAvailable, readCode]);- const { url: githubIssueUrl, omitted } = useMemo(() => {- if (!environment) {- return { url: Constants.bugReportUrl, omitted: [] as string[] };- }+ let githubIssueUrl = Constants.bugReportUrl;+ let omitted: string[] = [];+ if (environment) {const fields: Record<string, string> = {env: formatEnvironmentSection(environment),};@@ -158,8 +156,11 @@ export const FeedbackModal: React.FC<{if (includeCode && codeRequest.data) {fields["reproduction-code"] = formatCodeSection(codeRequest.data);}- return buildBugReportUrl(Constants.bugReportUrl, fields);- }, [environment, errors, includeErrors, includeCode, codeRequest.data]);+ ({ url: githubIssueUrl, omitted } = buildBugReportUrl(+ Constants.bugReportUrl,+ fields,+ ));+ }const omittedLabels = omitted.map((field) =>diff --git a/frontend/src/components/editor/code/__tests__/readonly-diff.test.tsx b/frontend/src/components/editor/code/__tests__/readonly-diff.test.tsxnew file mode 100644index 0000000000..3c740593d2--- /dev/null+++ b/frontend/src/components/editor/code/__tests__/readonly-diff.test.tsx@@ -0,0 +1,65 @@+/* Copyright 2026 Marimo. All rights reserved. */++import { render, screen } from "@testing-library/react";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { ReadonlyDiff } from "../readonly-diff";++const mocks = vi.hoisted(() => ({+ mergeView: vi.fn(),+ useTheme: vi.fn(),+}));++vi.mock("@codemirror/merge", () => ({+ unifiedMergeView: mocks.mergeView,+}));++vi.mock("@uiw/react-codemirror", () => ({+ default: ({ theme, value }: { theme: string; value: string }) => (+ <div data-testid="code-mirror" data-theme={theme} data-value={value} />+ ),+}));++vi.mock("@/theme/useTheme", () => ({+ useTheme: mocks.useTheme,+}));++describe("ReadonlyDiff", () => {+ beforeEach(() => {+ mocks.mergeView.mockReset();+ mocks.mergeView.mockReturnValue([]);+ mocks.useTheme.mockReturnValue({ theme: "light" });+ });++ it("updates modified code without rebuilding the diff extensions", () => {+ const { rerender } = render(+ <ReadonlyDiff original="before" modified="first revision" />,+ );++ expect(screen.getByTestId("code-mirror")).toHaveAttribute(+ "data-value",+ "first revision",+ );+ expect(mocks.mergeView).toHaveBeenCalledTimes(1);++ rerender(<ReadonlyDiff original="before" modified="second revision" />);++ expect(screen.getByTestId("code-mirror")).toHaveAttribute(+ "data-value",+ "second revision",+ );+ expect(mocks.mergeView).toHaveBeenCalledTimes(1);+ });++ it("rebuilds diff extensions when the original code changes", () => {+ const { rerender } = render(+ <ReadonlyDiff original="before" modified="after" />,+ );++ rerender(<ReadonlyDiff original="earlier" modified="after" />);++ expect(mocks.mergeView).toHaveBeenCalledTimes(2);+ expect(mocks.mergeView).toHaveBeenLastCalledWith(+ expect.objectContaining({ original: "earlier" }),+ );+ });+});diff --git a/frontend/src/components/editor/code/readonly-diff.tsx b/frontend/src/components/editor/code/readonly-diff.tsxindex 365a597724..017c1009e1 100644--- a/frontend/src/components/editor/code/readonly-diff.tsx+++ b/frontend/src/components/editor/code/readonly-diff.tsx@@ -21,7 +21,7 @@ export const ReadonlyDiff = memo(},}),];- }, [props.original, props.modified, theme]);+ }, [props.original]);return (<CodeMirrordiff --git a/frontend/src/components/editor/file-tree/__tests__/tree-actions.test.tsx b/frontend/src/components/editor/file-tree/__tests__/tree-actions.test.tsxnew file mode 100644index 0000000000..ee5d18b909--- /dev/null+++ b/frontend/src/components/editor/file-tree/__tests__/tree-actions.test.tsx@@ -0,0 +1,54 @@+/* Copyright 2026 Marimo. All rights reserved. */++import { act, fireEvent, render, screen } from "@testing-library/react";+import type React from "react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { RefreshIconButton } from "../tree-actions";++vi.mock("@/components/ui/tooltip", () => ({+ Tooltip: ({ children }: { children: React.ReactNode }) => children,+}));++describe("RefreshIconButton", () => {+ beforeEach(() => {+ vi.useFakeTimers();+ });++ afterEach(() => {+ vi.useRealTimers();+ });++ it("spins for at least 500ms after a refresh completes", async () => {+ const onClick = vi.fn().mockResolvedValue(undefined);+ const { container } = render(<RefreshIconButton onClick={onClick} />);++ fireEvent.click(screen.getByRole("button"));++ expect(onClick).toHaveBeenCalledOnce();+ expect(container.querySelector("svg")).toHaveClass("animate-[spin_0.5s]");++ await act(async () => {+ await vi.advanceTimersByTimeAsync(500);+ });++ expect(container.querySelector("svg")).not.toHaveClass(+ "animate-[spin_0.5s]",+ );+ });++ it("uses the latest refresh callback after a rerender", async () => {+ const initialOnClick = vi.fn().mockResolvedValue(undefined);+ const updatedOnClick = vi.fn().mockResolvedValue(undefined);+ const { rerender } = render(<RefreshIconButton onClick={initialOnClick} />);++ rerender(<RefreshIconButton onClick={updatedOnClick} />);+ fireEvent.click(screen.getByRole("button"));++ expect(initialOnClick).not.toHaveBeenCalled();+ expect(updatedOnClick).toHaveBeenCalledOnce();++ await act(async () => {+ await vi.advanceTimersByTimeAsync(500);+ });+ });+});diff --git a/frontend/src/components/editor/file-tree/tree-actions.tsx b/frontend/src/components/editor/file-tree/tree-actions.tsxindex d37a1b778a..380f22fcfc 100644--- a/frontend/src/components/editor/file-tree/tree-actions.tsx+++ b/frontend/src/components/editor/file-tree/tree-actions.tsx@@ -7,7 +7,7 @@ import {MoreVerticalIcon,RefreshCwIcon,} from "lucide-react";-import React, { useCallback, useState } from "react";+import React, { useState } from "react";import { Button, type ButtonProps } from "@/components/ui/button";import { Tooltip } from "@/components/ui/tooltip";import { cn } from "@/utils/cn";@@ -41,19 +41,16 @@ export const RefreshIconButton: React.FC<{}> = ({ onClick, tooltip = "Refresh", className, iconClassName }) => {const [isSpinning, setIsSpinning] = useState(false);- const handleClick = useCallback(- async (e: React.MouseEvent) => {- setIsSpinning(true);- // Artificially spin for 500ms to show the user that the button is working.- const minDelay = new Promise<void>((r) => setTimeout(r, 500));- try {- await Promise.all([onClick(e), minDelay]);- } finally {- setIsSpinning(false);- }- },- [onClick],- );+ const handleClick = async (e: React.MouseEvent) => {+ setIsSpinning(true);+ // Artificially spin for 500ms to show the user that the button is working.+ const minDelay = new Promise<void>((r) => setTimeout(r, 500));+ try {+ await Promise.all([onClick(e), minDelay]);+ } finally {+ setIsSpinning(false);+ }+ };const button = (<Buttondiff --git a/frontend/src/core/cells/pending-delete-service.ts b/frontend/src/core/cells/pending-delete-service.tsindex b8fff791ea..9984d3e2ea 100644--- a/frontend/src/core/cells/pending-delete-service.ts+++ b/frontend/src/core/cells/pending-delete-service.ts@@ -1,7 +1,6 @@/* Copyright 2026 Marimo. All rights reserved. */import { useAtomValue, useStore } from "jotai";-import { useMemo } from "react";import {useDeleteCellCallback,useDeleteManyCellsCallback,@@ -130,21 +129,18 @@ export function usePendingDeleteService() {const { entries } = useAtomValue(pendingDeleteStateAtom);const deleteCell = useDeleteCellCallback();const deleteManyCells = useDeleteManyCellsCallback();- return useMemo(- () => ({- submit: (cellIds: CellId[]) => {- submit({ cellIds, deleteCell, deleteManyCells, store });- },- clear,- get idle() {- return entries.size === 0;- },- get shouldConfirmDelete() {- return entries.size > 1;- },- }),- [store, submit, clear, entries, deleteCell, deleteManyCells],- );+ return {+ submit: (cellIds: CellId[]) => {+ submit({ cellIds, deleteCell, deleteManyCells, store });+ },+ clear,+ get idle() {+ return entries.size === 0;+ },+ get shouldConfirmDelete() {+ return entries.size > 1;+ },+ };}export function usePendingDelete(cellId: CellId) {