Skip to content

Commit e14d82a

Browse files
committed
fix(app): navigate outside the setState updater when closing a block tab
Closing a tab called navigate() from inside the setOpenTabs updater; updaters run during render, so the router state update fired React's "cannot update Transitioner while rendering Shell" warning.
1 parent ee1f78b commit e14d82a

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

app/src/routes/block.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,16 @@ function Shell() {
363363
};
364364
const closeTab = (id: number, e: React.MouseEvent) => {
365365
e.stopPropagation();
366-
setOpenTabs((t) => {
367-
const next = t.filter((x) => x !== id);
368-
if (activeId === id) {
369-
const nb = next[next.length - 1];
370-
void navigate(
371-
nb != null ? { to: "/block/$id", params: { id: String(nb) } } : { to: "/block" },
372-
);
373-
}
374-
return next;
375-
});
366+
// navigate OUTSIDE the state updater — updaters run during render, and
367+
// navigating there sets router state mid-render (React warns on it)
368+
const next = openTabs.filter((x) => x !== id);
369+
setOpenTabs(next);
370+
if (activeId === id) {
371+
const nb = next[next.length - 1];
372+
void navigate(
373+
nb != null ? { to: "/block/$id", params: { id: String(nb) } } : { to: "/block" },
374+
);
375+
}
376376
// Closing an untouched "New block" (no goal/recipes) discards it instead of
377377
// leaving an empty block behind. For the active tab we trust the editor's live
378378
// state (it may have unsaved edits the DB hasn't seen yet); for a background

0 commit comments

Comments
 (0)