fix(draft-order): don't crash the detail page when the actor is not a user - #16776
fix(draft-order): don't crash the detail page when the actor is not a user#16776breken-ai wants to merge 1 commit into
Conversation
… 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
|
|
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/.
Triggered by: new PR opened |
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 inconfirmed_by. The draft-order plugin'sActivityItempasseditem.userIdstraight touseUserregardless of prefix, and on a lookup failure it didthrow 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
Bycomponent convention (components/common/user-link/user-link.tsx: prefix-gate onuser_/cus_, return null otherwise) to the plugin's activity section:useUserwhen the actor id isuser_-prefixed (enabledgate, hooks stay unconditional)This is a port of the repo's own established pattern, not a new invention.
Verification
e9dc0ed): current code fetches anyuserIdand throwsisErrorinto the boundary; anapk_id 404s inuseUser.Bycomponent 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.