Skip to content

fix(draft-order): don't crash the detail page when the actor is not a user - #16776

Open
breken-ai wants to merge 1 commit into
medusajs:developfrom
breken-ai:fix-16775-draft-order-activity-apk-crash
Open

fix(draft-order): don't crash the detail page when the actor is not a user#16776
breken-ai wants to merge 1 commit into
medusajs:developfrom
breken-ai:fix-16775-draft-order-activity-apk-crash

Conversation

@breken-ai

Copy link
Copy Markdown

What changed

Fixes #16775 - draft order detail page crashes with 404: User with id apk_... was not found.

Root cause

Draft order changes confirmed via an admin API key store the apk_ id in confirmed_by. The draft-order plugin's ActivityItem passed item.userId straight to useUser regardless of prefix, and on a lookup failure it did throw error, which the error boundary turns into a full page crash. So one activity entry authored by an API key takes down the entire draft order detail page.

Fix

Ports the dashboard's own By component convention (components/common/user-link/user-link.tsx: prefix-gate on user_/cus_, return null otherwise) to the plugin's activity section:

  • only call useUser when the actor id is user_-prefixed (enabled gate, hooks stay unconditional)
  • never throw the lookup failure into the error boundary
  • skip the By-row when the actor is not a resolvable user; the skeleton still shows while a real user lookup is pending

This is a port of the repo's own established pattern, not a new invention.

Verification

  • Verified the crash path directly against develop HEAD (e9dc0ed): current code fetches any userId and throws isError into the boundary; an apk_ id 404s in useUser.
  • Verified the lineage claim: the dashboard By component prefix-gates and renders null for non-user/non-customer ids.

Honest limit: no render test - the admin dependency tree was not installable in our sandbox, so behavior was verified by direct code-path analysis plus an esbuild TSX transform of the patched file. CI will run the repo suites.

Built by breken, your AI support engineer - breken.ai - this one's on us.

… user

Draft order changes confirmed via an admin API key store the apk_ id in
confirmed_by. The draft-order admin plugin's ActivityItem passed it
straight to useUser, which 404s, and the error was thrown into the
error boundary, crashing the whole draft order detail page.

Port the dashboard's own By-component convention (prefix-gate on
user_, render null otherwise): only fetch real user ids, never throw a
failed lookup, and skip the By-row when the actor is not a resolvable
user. The skeleton still shows while the lookup is pending.

Fixes medusajs#16775
@breken-ai
breken-ai requested a review from a team as a code owner September 9, 2026 21:03
@changeset-bot

changeset-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f561a06

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@medusa-os-bot

medusa-os-bot Bot commented Sep 9, 2026

Copy link
Copy Markdown

Thanks for the contribution! A few items need to be addressed before this can move forward:

The PR fixes a real and verified bug in the draft-order plugin's activity section. When an order change is confirmed via an Admin API key, the confirmed_by field stores an apk_-prefixed ID rather than a user_-prefixed one. The original code passed any non-null userId to useUser, and when that fetch returned a 404, it threw the error directly into the React error boundary, crashing the entire draft order detail page. The fix prefix-gates the user fetch on user_-prefixed IDs (matching the established pattern in the dashboard's own By component in user-link.tsx) and removes the error-propagation. The logic is correct across all scenarios: null actor, non-user actor (apk_), user fetch pending, user loaded successfully, and user fetch error. No security or performance concerns were found — the change is a pure UI component fix with no server-side data flows. One blocking item: the PR is missing a changeset file, which is required for any source-code change under packages/.

  • A changeset is required for any source-code change under packages/. Run yarn changeset from the repo root and follow the prompts to add a patch changeset for @medusajs/draft-order. The changeset message should follow the format: fix(draft-order): <short description>.

Triggered by: new PR opened

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Draft order detail page crashes with 404 error (User with id: apk_01M0Z6297SC580MRQE3G9HCG4B was not found)

1 participant