danny-avila/LibreChat · warning · Error

Share ID is required

Error message

Share ID is required

What it means

Mirror of error 191 for the update path: the `useMutation` wrapping `dataService.updateSharedLink` requires `shareId` and throws synchronously if it is falsy, preventing a malformed PATCH/PUT to the server. The share ID identifies an existing shared link to update.

Source

Thrown at client/src/data-provider/mutations.ts:277

export const useUpdateSharedLinkMutation = (
  options?: t.MutationOptions<
    t.TUpdateShareLinkRequest,
    t.TUpdateShareLinkRequest & { snapshotFiles?: boolean }
  >,
): UseMutationResult<
  t.TSharedLinkResponse,
  unknown,
  t.TUpdateShareLinkRequest & { snapshotFiles?: boolean },
  unknown
> => {
  const queryClient = useQueryClient();

  const { onSuccess, ..._options } = options || {};
  return useMutation(
    ({ shareId, targetMessageId, snapshotFiles }) => {
      if (!shareId) {
        throw new Error('Share ID is required');
      }
      return dataService.updateSharedLink(shareId, targetMessageId, snapshotFiles);
    },
    {
      onSuccess: (_data: t.TSharedLinkResponse, vars, context) => {
        syncSharedLinkQueries(queryClient, _data, vars.snapshotFiles);

        onSuccess?.(_data, vars, context);
      },
      ..._options,
    },
  );
};

export const useDeleteSharedLinkMutation = (
  options?: t.DeleteSharedLinkOptions,
): UseMutationResult<
  t.TDeleteSharedLinkResponse,

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Ensure `shareId` is populated before enabling the update action — gate it on the share record being loaded.
  2. Render the edit form only after the share link exists (e.g. after `createSharedLink` resolves).
  3. If multiple shares exist, confirm the correct `shareId` is passed from the selected list item.

Example fix

// before
const updateShareLink = useUpdateShareLink();
useEffect(() => { if (shareId) updateShareLink.mutate({ shareId, ... }); }, [shareId]);
// after — only mutate once the shareId is known
useEffect(() => { if (!shareId) return; updateShareLink.mutate({ shareId, ... }); }, [shareId]);
Defensive patterns

Strategy: validation

Validate before calling

// Guard the call site
if (!shareId) throw new Error('Cannot update: no share selected');
updateShareLink.mutate({ shareId, ...patch });

Type guard

function hasShareId(v: unknown): v is { shareId: string } {
  return typeof v === 'object' && v !== null && typeof (v as any).shareId === 'string' && (v as any).shareId.length > 0;
}

Try / catch

// Gate the edit form on the share existing
if (!shareId) return;
updateShareLink.mutate({ shareId, ...patch });

Prevention

When it happens

Trigger: The update-share mutation is invoked before the share record has been loaded/created — e.g. an "edit share" form whose `shareId` prop is still `undefined` because the create call hasn't resolved, or a share-management UI opened without a selected link.

Common situations: Editing a shared link whose record hasn't been fetched yet; a list/detail view where no share is selected but the edit handler fired; refactor that dropped the `shareId` binding; calling update before the create mutation's `onSuccess` populated the ID.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/c7ab302233ef9064. Report an issue: GitHub.