diff --git a/app/components/Sidebar/components/CollectionRow.tsx b/app/components/Sidebar/components/CollectionRow.tsx index a72e1173fd..7b924383ad 100644 --- a/app/components/Sidebar/components/CollectionRow.tsx +++ b/app/components/Sidebar/components/CollectionRow.tsx @@ -2,6 +2,7 @@ import type { Location, LocationDescriptor } from "history"; import { observer } from "mobx-react"; import { PlusIcon } from "outline-icons"; import * as React from "react"; +import { flushSync } from "react-dom"; import { useTranslation } from "react-i18next"; import { mergeRefs } from "react-merge-refs"; import type { match } from "react-router"; @@ -149,7 +150,9 @@ function CollectionRow({ try { newChildTitleRef.current?.setIsEditing(false); await onCreateChild(value); - closeAddingNewChild(); + + // Remove the input in the same paint as the new tree item. + flushSync(closeAddingNewChild); } catch (_err) { newChildTitleRef.current?.setIsEditing(true); } diff --git a/app/components/Sidebar/components/DocumentRow.tsx b/app/components/Sidebar/components/DocumentRow.tsx index e446f3d803..3dc872f771 100644 --- a/app/components/Sidebar/components/DocumentRow.tsx +++ b/app/components/Sidebar/components/DocumentRow.tsx @@ -2,6 +2,7 @@ import type { Location, LocationDescriptor } from "history"; import { observer } from "mobx-react"; import { PlusIcon } from "outline-icons"; import * as React from "react"; +import { flushSync } from "react-dom"; import { useTranslation } from "react-i18next"; import type { match } from "react-router"; import styled from "styled-components"; @@ -194,7 +195,9 @@ function DocumentRow({ try { newChildTitleRef.current?.setIsEditing(false); await onCreateChild(value); - closeAddingNewChild(); + + // Remove the input in the same paint as the new tree item. + flushSync(closeAddingNewChild); } catch (_err) { newChildTitleRef.current?.setIsEditing(true); }