Skip to content

React Query error: "Query data cannot be undefined" in useTransitionOrderToState #3781

@nik71b14

Description

@nik71b14

Describe the bug
When viewing an Order in the Admin Dashboard, the console throws a runtime error because the React Query queryFn in useTransitionOrderToState may return undefined.
TanStack Query explicitly disallows undefined results.

To Reproduce
Steps to reproduce the behavior:

  1. Open the Admin Dashboard.
  2. Navigate to an Order that does not have a Modifying transition in its history.
  3. Open the browser console.
  4. See error.

Expected behavior
The hook should always return a defined value (null if no previous state is found) so that React Query does not throw.
No console error should appear.

Actual behavior
The function can return undefined, which causes React Query to throw:

Query data cannot be undefined. Please make sure to return a value other than undefined from your query function.
Affected query key: ["orderPreModifyingState","<id>"]

Screenshots/Videos
N/A

Error logs

Query data cannot be undefined. Please make sure to return a value other than undefined from your query function.
Affected query key: ["orderPreModifyingState","14"]

Environment (please complete the following information):

  • @vendure/core version: 3.4.1
  • Nodejs version: 22.16.0
  • Database: sqlite
  • Operating System: Linux (Ubuntu 24.04)
  • Browser: Firefox
  • Package manager: npm

Configuration

// No special configuration needed to reproduce

Minimal reproduction
Open an Order in the Admin Dashboard that does not contain a Modifying transition in its history.
The error will appear in the console.

Workaround
Locally patch the hook to ensure that the query function always returns a concrete value:

return (modifyingEntry?.data?.from as string | undefined) ?? null;

Also add:

  • useQuery<string | null> typing
  • enabled: !!orderId
  • placeholderData: null

Additional context

  • The bug is consistent and occurs whenever an order has no Modifying transition entry.
  • Fixing this improves robustness of the dashboard and avoids runtime errors.

I intend to work on a fix for this issue and submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions