From 4d4e99456283ff6f4806b5d9834da638110aa6d6 Mon Sep 17 00:00:00 2001 From: James Brunton Date: Tue, 14 Jul 2026 10:09:23 +0100 Subject: [PATCH] Fix crash in Processor when loading tool settings with tooltips (#7015) # Description of Changes Some of the tool settings make use of editor preferences indirectly, but the Processor never gets that provider, so it crashes when trying to load them. --- .../pipelines/PipelineStepSettings.test.tsx | 52 +++++++++++++++++++ .../pipelines/PipelineStepSettings.tsx | 24 +++++---- 2 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 frontend/editor/src/portal/components/pipelines/PipelineStepSettings.test.tsx diff --git a/frontend/editor/src/portal/components/pipelines/PipelineStepSettings.test.tsx b/frontend/editor/src/portal/components/pipelines/PipelineStepSettings.test.tsx new file mode 100644 index 0000000000..698fb0028a --- /dev/null +++ b/frontend/editor/src/portal/components/pipelines/PipelineStepSettings.test.tsx @@ -0,0 +1,52 @@ +import { describe, expect, it, vi } from "vitest"; +import { render, screen } from "@testing-library/react"; +import { MantineProvider } from "@mantine/core"; +import { Tooltip } from "@app/components/shared/Tooltip"; +import type { ToolRegistry } from "@app/data/toolsTaxonomy"; +import type { WorkingToolStep } from "@app/hooks/tools/shared/toolAutomation"; +import { PipelineStepSettings } from "@portal/components/pipelines/PipelineStepSettings"; + +vi.mock("react-i18next", () => ({ + useTranslation: () => ({ + t: (key: string, fallback?: string) => fallback ?? key, + }), +})); + +// A stand-in tool-settings UI that uses the shared editor Tooltip. The Tooltip +// pulls in the Preferences + Sidebar contexts, which the portal does not mount +// app-wide — so this reproduces the "usePreferences must be used within a +// PreferencesProvider" crash unless PipelineStepSettings supplies them. +function TooltipSettings() { + return ( + + + + ); +} + +const step = { + support: "editable", + toolId: "compress", + params: {}, +} as unknown as WorkingToolStep; + +const registry = { + compress: { automationSettings: TooltipSettings }, +} as unknown as Partial; + +describe("PipelineStepSettings", () => { + it("renders reused editor tool settings (which use the shared Tooltip) without app-wide Preferences/Sidebar providers", () => { + expect(() => + render( + + {}} + /> + , + ), + ).not.toThrow(); + expect(screen.getByText("field")).toBeInTheDocument(); + }); +}); diff --git a/frontend/editor/src/portal/components/pipelines/PipelineStepSettings.tsx b/frontend/editor/src/portal/components/pipelines/PipelineStepSettings.tsx index fe2ee9dd2a..672383ecd3 100644 --- a/frontend/editor/src/portal/components/pipelines/PipelineStepSettings.tsx +++ b/frontend/editor/src/portal/components/pipelines/PipelineStepSettings.tsx @@ -1,6 +1,8 @@ import { Suspense } from "react"; import { useTranslation } from "react-i18next"; import { Banner } from "@app/ui"; +import { PreferencesProvider } from "@app/contexts/PreferencesContext"; +import { SidebarProvider } from "@app/contexts/SidebarContext"; import { type ToolRegistry } from "@app/data/toolsTaxonomy"; import { type ErasedToolParams } from "@app/hooks/tools/shared/toolOperationTypes"; import { type WorkingToolStep } from "@app/hooks/tools/shared/toolAutomation"; @@ -46,14 +48,18 @@ export function PipelineStepSettings({ } return ( - - - onChange({ ...step.params, [key]: value }) - } - disabled={false} - /> - + + + + + onChange({ ...step.params, [key]: value }) + } + disabled={false} + /> + + + ); }