Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
📝 fix: Preserve Chat Drafts Across Navigation and Clearing (#16161)
Danny Avila6f30170a79fb
diff --git a/client/src/hooks/Input/useAutoSave.spec.ts b/client/src/hooks/Input/useAutoSave.spec.tsindex ce3730e565..857c0588bc 100644--- a/client/src/hooks/Input/useAutoSave.spec.ts+++ b/client/src/hooks/Input/useAutoSave.spec.ts@@ -36,6 +36,7 @@ import { useGetFiles } from '~/data-provider';import { hasInFlightUpload } from '~/hooks/Files/useFileHandling';import {encodeBase64,+ clearDraft,clearAllDrafts,getAskAnswerDraftId,getDraft,@@ -509,8 +510,7 @@ describe('useAutoSave — typing as a run finishes', () => {expect(mockSetValue).toHaveBeenLastCalledWith('text', 'a whole sentence typed quickly');});- /** A draft of one character is deliberately not persisted, so the record cannot speak for the- * composer here. The composer still can, and it is what the user is looking at. */+ /** A debounced record can still lag the character visible in the composer at run end. */it('keeps a single character typed as the run ends', () => {const textAreaRef = makeTextAreaRef();const { rerender } = renderHook(@@ -1166,3 +1166,50 @@ describe('useAutoSave — file cache updates', () => {expect(mockSetValue).toHaveBeenCalledWith('text', 'closed tab text');});});++describe('useAutoSave — exact text across navigation', () => {+ const draftStorage = jest.requireActual<typeof import('~/utils/drafts')>('~/utils/drafts');++ beforeEach(() => {+ mockGetDraft.mockImplementation(draftStorage.getDraft);+ mockSetDraft.mockImplementation(draftStorage.setDraft);+ (clearDraft as jest.Mock).mockImplementation(draftStorage.clearDraft);+ });++ afterEach(() => {+ mockGetDraft.mockReset();+ mockSetDraft.mockReset();+ (clearDraft as jest.Mock).mockReset();+ });++ it.each(['x', '字', ' ', '\n', 'first line\nsecond line'])(+ 'restores %j after switching through an empty conversation and new chat',+ (value) => {+ const textarea = document.createElement('textarea');+ const textAreaRef = { current: textarea };+ const files = new Map<string, never>();+ const setFiles = jest.fn();+ mockSetValue.mockImplementation((_name: string, text: string) => {+ textarea.value = text;+ });+ const { rerender } = renderHook(+ ({ conversationId }: { conversationId: string }) =>+ useAutoSave({ conversationId, textAreaRef, files, setFiles }),+ { initialProps: { conversationId: 'convo-exact' } },+ );+ textarea.value = value;+ act(() => rerender({ conversationId: 'convo-empty' }));+ expect(textarea.value).toBe('');+ expect(draftStorage.getDraft('convo-exact')).toBe(value);+ act(() => rerender({ conversationId: String(Constants.NEW_CONVO) }));+ expect(textarea.value).toBe('');+ act(() => rerender({ conversationId: 'convo-exact' }));+ expect(textarea.value).toBe(value);+ textarea.value = '';+ act(() => rerender({ conversationId: 'convo-empty' }));+ act(() => rerender({ conversationId: 'convo-exact' }));+ expect(textarea.value).toBe('');+ mockSetValue.mockReset();+ },+ );+});diff --git a/client/src/hooks/Input/useAutoSave.ts b/client/src/hooks/Input/useAutoSave.tsindex b088d0c5f2..77318cf9b3 100644--- a/client/src/hooks/Input/useAutoSave.ts+++ b/client/src/hooks/Input/useAutoSave.ts@@ -194,7 +194,7 @@ export const useAutoSave = ({return;}// Save the draft of the current conversation before switching- if (textAreaRef.current.value === '' || textAreaRef.current.value.length === 1) {+ if (textAreaRef.current.value === '') {clearDraft(id);} else {setDraft({ id, value: textAreaRef.current.value });@@ -354,14 +354,12 @@ export const useAutoSave = ({/** Move the pending text draft to the new conversationId, then let the composer correct* it. Both describe the same composer and the record is a debounced copy of it, so when* they disagree the record is simply older, and restoring it would roll the user's last- * keystrokes back mid-sentence. `persistExact` because a one-character message is still- * the user's message, and the ordinary threshold would refuse to keep it. An empty- * composer defers to the record instead: a steer consumes the text and clears the- * composer programmatically, and run end must not undo that. */+ * keystrokes back mid-sentence. An empty composer defers to the record instead: a steer+ * consumes the text and clears the composer programmatically, and run end must not undo that. */migrateTextDraft(pendingDraftId, conversationId);const liveText = textAreaRef?.current?.value ?? '';if (liveText !== '' && getDraft(conversationId) !== liveText) {- setDraft({ id: conversationId, value: liveText, persistExact: true });+ setDraft({ id: conversationId, value: liveText });}filesDraftId = migrateFilesDraft(pendingDraftId, conversationId);} else {diff --git a/client/src/hooks/Input/useTextarea.ts b/client/src/hooks/Input/useTextarea.tsindex 52218585e5..73e960766d 100644--- a/client/src/hooks/Input/useTextarea.ts+++ b/client/src/hooks/Input/useTextarea.ts@@ -471,7 +471,7 @@ export default function useTextarea({if (saveDrafts && isFilesDraftOwnedByThisTab(getFilesDraft(draftId))) {addPastedTextDraftFile({ id: draftId, fileId: pendingFileId });try {- setDraft({ id: draftId, value: composerValue, persistExact: true });+ setDraft({ id: draftId, value: composerValue });setPendingTextAttachmentDraft({id: draftId,fileId: pendingFileId,diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.jsonindex 61a40b034d..db1d8a3aed 100644--- a/client/src/locales/en/translation.json+++ b/client/src/locales/en/translation.json@@ -1257,6 +1257,7 @@"com_ui_conversation": "conversation","com_ui_conversation_label": "{{title}} conversation","com_ui_conversation_label_shared": "{{title}} conversation, shared link active",+ "com_ui_conversation_load_error": "Could not load this chat. Please try again.","com_ui_conversation_not_found": "Conversation not found","com_ui_conversation_summarized": "Conversation summarized","com_ui_conversations": "conversations",diff --git a/client/src/routes/ChatRoute.tsx b/client/src/routes/ChatRoute.tsxindex 837227bc35..e4236fe194 100644--- a/client/src/routes/ChatRoute.tsx+++ b/client/src/routes/ChatRoute.tsx@@ -1,8 +1,8 @@-import { useEffect, useMemo } from 'react';+import { useEffect, useMemo, useState } from 'react';import { useQueryClient } from '@tanstack/react-query';import { useRecoilCallback, useRecoilValue } from 'recoil';-import { Spinner, useToastContext } from '@librechat/client';import { useParams, useSearchParams } from 'react-router-dom';+import { Button, Spinner, useToastContext } from '@librechat/client';import { useGetModelsQuery } from 'librechat-data-provider/react-query';import {Constants,@@ -68,6 +68,18 @@ export default function ChatRoute() {const chatProjectId = isValidChatProjectId(projectIdParam) ? projectIdParam : null;useIdChangeEffect(conversationId);const { hasSetConversation, conversation } = store.useCreateConversationAtom(index);+ const [routeState, setRouteState] = useState({+ conversationId,+ pending: conversation != null && conversation.conversationId !== conversationId,+ });+ /** History navigation changes the route without running the sidebar's conversation setter.+ * Only a route change may request reconciliation: a newly submitted conversation can acquire+ * its server id before the URL catches up, and must not be reset to a new chat. */+ if (routeState.conversationId !== conversationId) {+ setRouteState({ conversationId, pending: conversation?.conversationId !== conversationId });+ } else if (routeState.pending && conversation?.conversationId === conversationId) {+ setRouteState({ conversationId, pending: false });+ }const mcpWarmupAllowed =conversation != null &&!(isAgentsEndpoint(conversation.endpoint) && isEphemeralAgentId(conversation.agent_id ?? ''));@@ -131,7 +143,9 @@ export default function ChatRoute() {});const initialConvoQuery = useGetConvoIdQuery(conversationId, {enabled:- isAuthenticated && conversationId !== Constants.NEW_CONVO && !hasSetConversation.current,+ isAuthenticated &&+ conversationId !== Constants.NEW_CONVO &&+ (!hasSetConversation.current || routeState.pending),});const endpointsQuery = useGetEndpointsQuery({ enabled: isAuthenticated });const assistantListMap = useAssistantListMap();@@ -174,7 +188,7 @@ export default function ChatRoute() {const shouldSetConvo =(startupConfig &&rolesLoaded &&- (!hasSetConversation.current || newConvoNeedsInit) &&+ (!hasSetConversation.current || newConvoNeedsInit || routeState.pending) &&!modelsQuery.data?.initial) ??false;/* Early exit if startupConfig is not loaded and conversation is already set and only initial models have loaded */@@ -295,6 +309,7 @@ export default function ChatRoute() {});hasSetConversation.current = true;} else if (+ initialConvoQuery.data &&assistantListMap[EModelEndpoint.assistants] &&assistantListMap[EModelEndpoint.azureAssistants]) {@@ -309,6 +324,8 @@ export default function ChatRoute() {/* Creates infinite render if all dependencies included due to newConversation invocations exceeding call stack before hasSetConversation.current becomes truthy */// eslint-disable-next-line react-hooks/exhaustive-deps}, [+ conversationId,+ routeState.pending,roles,agentsMap,agentsQuery.isError,@@ -354,7 +371,23 @@ export default function ChatRoute() {return (<ToolCallsMapProvider conversationId={conversation.conversationId ?? ''}>- <ChatView index={index} project={verifiedChatProjectId ? projectQuery.data : undefined} />+ {routeState.pending && (+ <div className="flex h-screen items-center justify-center" aria-live="polite" role="status">+ {initialConvoQuery.isError && !initialConvoQuery.isFetching ? (+ <div className="flex flex-col items-center gap-3" role="alert">+ <p>{localize('com_ui_conversation_load_error')}</p>+ <Button onClick={() => initialConvoQuery.refetch()}>+ {localize('com_ui_retry')}+ </Button>+ </div>+ ) : (+ <Spinner className="text-text-primary" />+ )}+ </div>+ )}+ <div hidden={routeState.pending} className={routeState.pending ? 'hidden' : 'contents'}>+ <ChatView index={index} project={verifiedChatProjectId ? projectQuery.data : undefined} />+ </div></ToolCallsMapProvider>);}diff --git a/client/src/routes/__tests__/ChatRoute.spec.tsx b/client/src/routes/__tests__/ChatRoute.spec.tsxnew file mode 100644index 0000000000..76aff766b5--- /dev/null+++ b/client/src/routes/__tests__/ChatRoute.spec.tsx@@ -0,0 +1,233 @@+import React from 'react';+import { createMemoryRouter, RouterProvider } from 'react-router-dom';+import { QueryClient, QueryClientProvider } from '@tanstack/react-query';+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';+import type { TConversation } from 'librechat-data-provider';+import ChatRoute from '../ChatRoute';++const mockSetConversation = jest.fn();+const mockFetchConversation = jest.fn();+const mockHasSetConversation = { current: true };+let mockConversation: Partial<TConversation> = { conversationId: 'chat-a' };+const mockConfig = {};+const mockRoles = { USER: {} };+let mockAssistantListMap = {};+const mockNewConversation = jest.fn(({ template }: { template?: Partial<TConversation> }) => {+ mockConversation = { conversationId: 'new', ...template };+ mockSetConversation();+});++jest.mock('recoil', () => ({+ useRecoilValue: () => false,+ useRecoilCallback: () => () => {},+}));+jest.mock('~/store', () => ({+ __esModule: true,+ default: {+ useCreateConversationAtom: () => ({+ conversation: mockConversation,+ hasSetConversation: mockHasSetConversation,+ }),+ },+}));+jest.mock('~/store/temporary', () => ({ __esModule: true, default: {} }));+jest.mock('../useAuthRedirect', () => ({+ __esModule: true,+ default: () => ({ isAuthenticated: true, roles: mockRoles }),+}));+jest.mock('librechat-data-provider/react-query', () => ({+ useGetModelsQuery: () => ({ data: mockConfig }),+}));+jest.mock('~/data-provider', () => ({+ useGetStartupConfig: () => ({ data: mockConfig }),+ useGetEndpointsQuery: () => ({ data: mockConfig }),+ useListAgentsQuery: () => ({}),+ useProjectQuery: () => ({}),+ useGetConvoIdQuery: (id: string, options: { enabled: boolean }) => {+ const { useQuery: query } = jest.requireActual('@tanstack/react-query');+ return query(['conversation', id], () => mockFetchConversation(id), {+ ...options,+ retry: false,+ staleTime: Infinity,+ });+ },+}));+jest.mock('~/hooks', () => ({+ useAssistantListMap: () => mockAssistantListMap,+ useIdChangeEffect: () => {},+ useAppStartup: () => {},+ useNewConvo: () => ({ newConversation: mockNewConversation }),+ useLocalize: () => (key: string) => key,+}));+jest.mock('~/Providers', () => ({+ ToolCallsMapProvider: ({ children }: { children: React.ReactNode }) => children,+ useAgentsMapContext: () => mockConfig,+}));+jest.mock('@librechat/client', () => ({+ Spinner: () => <span />,+ Button: (props: React.ButtonHTMLAttributes<HTMLButtonElement>) => <button {...props} />,+ useToastContext: () => ({ showToast: jest.fn() }),+}));+jest.mock('~/utils', () => ({+ defaultSpecAwaitsAgents: () => false,+ processValidSettings: () => ({}),+ getDefaultModelSpec: () => ({}),+ hasModelSelection: () => false,+ isNotFoundError: () => false,+ isTemporaryConversation: () => false,+ clearMessagesCache: jest.fn(),+ logger: { log: jest.fn() },+}));+jest.mock('~/components/Chat/ChatView', () => ({+ __esModule: true,+ default: () => <div data-testid="composer">{mockConversation.conversationId}</div>,+}));++function Harness() {+ const [, update] = React.useReducer((n: number) => n + 1, 0);+ mockSetConversation.mockImplementation(update);+ return <ChatRoute />;+}++function setup(initialEntries = ['/c/chat-a'], initialIndex = initialEntries.length - 1) {+ const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });+ const router = createMemoryRouter([{ path: '/c/:conversationId', element: <Harness /> }], {+ initialEntries,+ initialIndex,+ });+ render(+ <QueryClientProvider client={client}>+ <RouterProvider router={router} />+ </QueryClientProvider>,+ );+ return { client, router };+}++beforeEach(() => {+ mockConversation = { conversationId: 'chat-a' };+ mockHasSetConversation.current = true;+ mockAssistantListMap = {};+ mockFetchConversation.mockImplementation(async (id: string) => ({ conversationId: id }));+});++it('reconciles Back and Forward with each route, including new chat', async () => {+ const { router } = setup(['/c/new', '/c/chat-b', '/c/chat-a']);+ await act(async () => {+ await router.navigate(-1);+ });+ await waitFor(() => expect(screen.getByTestId('composer')).toHaveTextContent('chat-b'));+ await act(async () => {+ await router.navigate(-1);+ });+ await waitFor(() => expect(screen.getByTestId('composer')).toHaveTextContent('new'));+ await act(async () => {+ await router.navigate(1);+ });+ await waitFor(() => expect(screen.getByTestId('composer')).toHaveTextContent('chat-b'));+});++it('does not reset a new conversation when its server id arrives before the URL', async () => {+ mockConversation = { conversationId: 'new' };+ const { router } = setup(['/c/new']);+ act(() => {+ mockConversation = { conversationId: 'created-chat' };+ mockSetConversation();+ });+ expect(mockNewConversation).not.toHaveBeenCalled();+ await act(async () => {+ await router.navigate('/c/created-chat', { replace: true });+ });+ expect(mockNewConversation).not.toHaveBeenCalled();+ expect(mockFetchConversation).not.toHaveBeenCalled();+});++it('reuses the full cached record when returning through history', async () => {+ const { client, router } = setup(['/c/chat-b', '/c/chat-a']);+ client.setQueryData(['conversation', 'chat-b'], {+ conversationId: 'chat-b',+ model: 'saved-model',+ });+ await act(async () => {+ await router.navigate(-1);+ });+ await waitFor(() =>+ expect(mockConversation).toMatchObject({ conversationId: 'chat-b', model: 'saved-model' }),+ );+ expect(mockFetchConversation).not.toHaveBeenCalled();+});++it('keeps the departing composer mounted but hidden until the destination record arrives', async () => {+ let resolveRecord: (value: Partial<TConversation>) => void = () => {};+ mockFetchConversation.mockReturnValue(+ new Promise<Partial<TConversation>>((resolve) => {+ resolveRecord = resolve;+ }),+ );+ const { router } = setup(['/c/chat-b', '/c/chat-a']);+ const composer = screen.getByTestId('composer');+ await act(async () => {+ await router.navigate(-1);+ });+ expect(screen.getByTestId('composer')).toBe(composer);+ expect(composer).not.toBeVisible();+ await act(async () => {+ resolveRecord({ conversationId: 'chat-b' });+ });+ await waitFor(() => expect(composer).toBeVisible());+ expect(composer).toHaveTextContent('chat-b');+});++it('ignores a response for a route left while its record was loading', async () => {+ let resolveRecord: (value: Partial<TConversation>) => void = () => {};+ mockFetchConversation.mockReturnValue(+ new Promise<Partial<TConversation>>((resolve) => {+ resolveRecord = resolve;+ }),+ );+ const { router } = setup(['/c/chat-b', '/c/chat-a']);+ await act(async () => {+ await router.navigate(-1);+ });+ await act(async () => {+ await router.navigate(1);+ });+ await act(async () => {+ resolveRecord({ conversationId: 'chat-b' });+ });+ expect(screen.getByTestId('composer')).toHaveTextContent('chat-a');+ expect(mockNewConversation).not.toHaveBeenCalled();+});++it('allows retry after a failed history load without replacing the departing draft', async () => {+ const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});+ mockFetchConversation.mockRejectedValueOnce(new Error('offline'));+ const { router } = setup(['/c/chat-b', '/c/chat-a']);+ await act(async () => {+ await router.navigate(-1);+ });+ await screen.findByRole('alert');+ expect(mockConversation.conversationId).toBe('chat-a');+ expect(screen.getByTestId('composer')).not.toBeVisible();+ fireEvent.click(screen.getByRole('button', { name: 'com_ui_retry' }));+ await waitFor(() => expect(screen.getByTestId('composer')).toBeVisible());+ expect(mockConversation.conversationId).toBe('chat-b');+ expect(consoleError).toHaveBeenCalledWith(new Error('offline'));+});++it('waits for the conversation record even when assistant catalogs are already loaded', async () => {+ mockAssistantListMap = { assistants: {}, azureAssistants: {} };+ mockFetchConversation.mockReturnValue(new Promise(() => {}));+ const { router } = setup(['/c/chat-b', '/c/chat-a']);+ await act(async () => {+ await router.navigate(-1);+ });+ expect(mockNewConversation).not.toHaveBeenCalled();+ expect(mockConversation.conversationId).toBe('chat-a');+ expect(screen.getByTestId('composer')).not.toBeVisible();+});++it('reconciles a remounted chat route with conversation state retained by the shell', async () => {+ setup(['/c/chat-b']);+ await waitFor(() => expect(screen.getByTestId('composer')).toHaveTextContent('chat-b'));+ expect(mockFetchConversation).toHaveBeenCalledWith('chat-b');+});diff --git a/client/src/utils/drafts.spec.ts b/client/src/utils/drafts.spec.tsindex 1cc6e6ae86..2e0fe23b30 100644--- a/client/src/utils/drafts.spec.ts+++ b/client/src/utils/drafts.spec.ts@@ -3,6 +3,7 @@ import {applyPendingPasteToDraft,applyPendingPastesToDraft,clearAllDrafts,+ clearDraft,clearComposerDrafts,clearFilesDraft,decodeBase64,@@ -945,33 +946,35 @@ describe('migrateTextDraft', () => {});});-describe('setDraft persistExact', () => {+describe('setDraft', () => {beforeEach(() => {localStorage.clear();});- it('drops a one-character value by default', () => {+ it.each(['x', '字', ' ', '\n', '🙂', 'line one\nline two'])(+ 'preserves the exact draft %j',+ (value) => {+ setDraft({ id: 'convo-1', value });+ expect(getDraft('convo-1')).toBe(value);+ },+ );++ it('clears a draft only when its value is empty', () => {setDraft({ id: 'convo-1', value: 'x' });+ setDraft({ id: 'convo-1', value: '' });expect(getDraft('convo-1')).toBe('');});- it('keeps a one-character snapshot when persistExact is set', () => {- setDraft({ id: 'convo-1', value: 'x', persistExact: true });- expect(getDraft('convo-1')).toBe('x');- });-it('does not throw when localStorage.setItem fails', () => {const setItem = jest.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {throw new Error('quota exceeded');});- expect(() =>- setDraft({ id: 'convo-1', value: 'draft text', persistExact: true }),- ).not.toThrow();+ expect(() => setDraft({ id: 'convo-1', value: 'draft text' })).not.toThrow();setItem.mockRestore();});it('returns empty drafts when localStorage.getItem throws', () => {- setDraft({ id: 'convo-1', value: 'draft text', persistExact: true });+ setDraft({ id: 'convo-1', value: 'draft text' });setFilesDraft('convo-1', {fileIds: ['file-1'],pendingPastes: { 'file-1': { text: 'paste', selectionStart: 0 } },@@ -1088,3 +1091,32 @@ describe('resolvePendingPasteInsertStart', () => {).toBe(0);});});++describe('clearDraft navigation ordering', () => {+ beforeEach(() => {+ localStorage.clear();+ jest.useFakeTimers();+ });+ afterEach(() => {+ jest.useRealTimers();+ });++ it('cannot delete text written after returning to a cleared conversation', () => {+ setDraft({ id: 'chat-a', value: 'old draft' });+ clearDraft('chat-a');+ expect(getDraft('chat-a')).toBe('');+ setDraft({ id: 'chat-a', value: 'replacement draft' });+ jest.advanceTimersByTime(3000);+ expect(getDraft('chat-a')).toBe('replacement draft');+ });++ it('clears two different conversations without cancelling either deletion', () => {+ setDraft({ id: 'chat-a', value: 'alpha' });+ setDraft({ id: 'chat-b', value: 'beta' });+ clearDraft('chat-a');+ clearDraft('chat-b');+ jest.advanceTimersByTime(3000);+ expect(getDraft('chat-a')).toBe('');+ expect(getDraft('chat-b')).toBe('');+ });+});diff --git a/client/src/utils/drafts.ts b/client/src/utils/drafts.tsindex facd6ec107..2fc8e96421 100644--- a/client/src/utils/drafts.ts+++ b/client/src/utils/drafts.ts@@ -1,4 +1,3 @@-import debounce from 'lodash/debounce';import { Constants, LocalStorageKeys } from 'librechat-data-provider';import { isPasteSubmitted } from './files';@@ -288,13 +287,14 @@ const removeLocalStorageItem = (key: string): void => {}};-export const clearDraft = debounce((id?: string | null) => {+/** Navigation must clear before another visit can save replacement text under the same key. */+export const clearDraft = (id?: string | null) => {const key = id ?? '';if (!mayClearComposerDrafts(key)) {return;}removeLocalStorageItem(`${LocalStorageKeys.TEXT_DRAFT}${key}`);-}, 2500);+};/** Synchronously removes both text and file drafts for a conversation (or NEW_CONVO fallback).* A record another live tab owns is left alone, attachment or not: every key here is reachable@@ -1214,18 +1214,8 @@ export const removePendingTextAttachmentDraft = ({});};-export const setDraft = ({- id,- value,- persistExact = false,-}: {- id: string;- value?: string;- persistExact?: boolean;-}) => {- const shouldPersist = persistExact- ? value != null && value.length > 0- : value && value.length > 1;+export const setDraft = ({ id, value }: { id: string; value?: string }) => {+ const shouldPersist = value != null && value.length > 0;if (shouldPersist) {/** A refused key belongs to another open tab holding it against attachments it still has.* This tab could not restore what it wrote there anyway, so the write would only destroy that