Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(views): keep the Save as view name while the host re-renders (MUL-7756) (#8885)
Jiayuan Zhange427ed7dfbc1
diff --git a/packages/views/issues/components/issues-header.tsx b/packages/views/issues/components/issues-header.tsxindex 752264cc28..c080ac5cf1 100644--- a/packages/views/issues/components/issues-header.tsx+++ b/packages/views/issues/components/issues-header.tsx@@ -1263,10 +1263,7 @@ export function IssuesHeader({);// The save dialog's default variant: while a saved view is open the view's// own variant wins (the rows on screen ARE that variant — a copy must not- // silently widen to the page tab); otherwise the page tab applies. Memoized- // on primitives: the dialog resets its draft when this prop's identity- // changes, so a fresh object per header render would wipe a half-typed- // name on any background refetch.+ // silently widen to the page tab); otherwise the page tab applies.const dialogActorKind = activeView? actorKindForViewVariant(activeView.scope_variant): scope;diff --git a/packages/views/issues/components/save-view-dialog.test.tsx b/packages/views/issues/components/save-view-dialog.test.tsxindex 2f88edef91..5c9dcde3be 100644--- a/packages/views/issues/components/save-view-dialog.test.tsx+++ b/packages/views/issues/components/save-view-dialog.test.tsx@@ -8,7 +8,7 @@ import {} from "@multica/core/issues/stores/view-store";import { ViewStoreProvider } from "@multica/core/issues/stores/view-store-context";import { renderWithI18n } from "../../test/i18n";-import { DraftDefinitionFields } from "./save-view-dialog";+import { DraftDefinitionFields, SaveViewDialog } from "./save-view-dialog";vi.mock("@tanstack/react-query", async (importOriginal) => ({...(await importOriginal<typeof import("@tanstack/react-query")>()),@@ -19,6 +19,11 @@ vi.mock("@multica/core/hooks", () => ({useWorkspaceId: () => "workspace-1",}));+vi.mock("@multica/core/issue-views/mutations", () => ({+ useCreateIssueView: () => ({ mutate: vi.fn(), isPending: false }),+ useUpdateIssueView: () => ({ mutate: vi.fn(), isPending: false }),+}));+vi.mock("./issues-header", () => ({IssueFilterMenu: ({ trigger }: { trigger: React.ReactNode }) => trigger,}));@@ -62,3 +67,38 @@ describe("DraftDefinitionFields ordering", () => {).not.toBeInTheDocument();});});++describe("SaveViewDialog draft lifecycle", () => {+ const liveStore = createStore<IssueViewState>()(viewStoreSlice);+ // Hosts build `scope` inline, so every host render passes a new object.+ const dialog = (open: boolean) => (+ <ViewStoreProvider store={liveStore}>+ <SaveViewDialog+ open={open}+ onOpenChange={() => {}}+ scope={{ kind: "my", variant: "assigned" }}+ />+ </ViewStoreProvider>+ );++ it("keeps a half-typed name when the host re-renders", async () => {+ const user = userEvent.setup();+ const { rerender } = renderWithI18n(dialog(true));++ await user.type(screen.getByLabelText("Name"), "Ongoing");+ rerender(dialog(true));++ expect(screen.getByLabelText("Name")).toHaveValue("Ongoing");+ });++ it("starts from a blank name on the next open", async () => {+ const user = userEvent.setup();+ const { rerender } = renderWithI18n(dialog(true));++ await user.type(screen.getByLabelText("Name"), "Ongoing");+ rerender(dialog(false));+ rerender(dialog(true));++ expect(screen.getByLabelText("Name")).toHaveValue("");+ });+});diff --git a/packages/views/issues/components/save-view-dialog.tsx b/packages/views/issues/components/save-view-dialog.tsxindex 42d3949ded..89a55981d6 100644--- a/packages/views/issues/components/save-view-dialog.tsx+++ b/packages/views/issues/components/save-view-dialog.tsx@@ -488,6 +488,10 @@ export function SaveViewDialog({// Fresh draft per open: seed a private store instance from the live// panel's data fields, then let the embedded controls mutate it freely.+ // Keyed on `open` alone: hosts rebuild `scope` on every render, and+ // re-seeding on prop identity would wipe a half-typed name (and draft+ // filters) on any background refetch. Hosts set `editView` and `open` in+ // the same event, so the values read here are the ones this open is for.useEffect(() => {if (!open) {setDraftStore(null);@@ -526,7 +530,8 @@ export function SaveViewDialog({: scope.variant,);}- }, [open, liveStore, editView, seedFromDefinition, scope]);+ // eslint-disable-next-line react-hooks/exhaustive-deps -- seed once per open, see above+ }, [open]);const { data: projects = [] } = useQuery({...projectListOptions(wsId),