Skip to content

fix: preserve seed data _id as stable record id across page refreshes#950

Merged
hotlong merged 3 commits intomainfrom
copilot/fix-opportunity-record-not-found
Mar 2, 2026
Merged

fix: preserve seed data _id as stable record id across page refreshes#950
hotlong merged 3 commits intomainfrom
copilot/fix-opportunity-record-not-found

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

Detail page shows "Record not found" on browser refresh because the in-memory MSW kernel reboots with new timestamp-based IDs, invalidating the ID in the URL.

Root cause

syncDriverIds() unconditionally overwrites seed data's stable _id (e.g. "101") with the driver-generated id (e.g. "opportunity-1772422975850-6"). On refresh, a new kernel generates different timestamps → old URL IDs are orphaned.

// Before: always overwrites seed _id
record._id = record.id;

// After: promotes seed _id to canonical id when present
if (record._id != null && record._id !== record.id) {
  record.id = record._id;
} else if (record.id) {
  record._id = record.id;
}

Changes

  • apps/console/src/mocks/createKernel.tssyncDriverIds now promotes explicit seed _id to id, keeping record identifiers stable across kernel reboots
  • packages/data-objectstack/src/index.ts — Defensive array handling in findOne $expand path, consistent with normalizeQueryResult for find()
  • apps/console/src/__tests__/MSWServer.test.tsx — Tests verifying seed IDs are preserved and records are fetchable by stable _id via HTTP
Original prompt

https://demo.objectui.org/apps/crm_app/opportunity/record/opportunity-1772422975850-6 进入详情页刷新显示record not found


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectui Ready Ready Preview, Comment Mar 2, 2026 4:21am
objectui-demo Ready Ready Preview, Comment Mar 2, 2026 4:21am
objectui-storybook Ready Ready Preview, Comment Mar 2, 2026 4:21am

Request Review

Copilot AI and others added 2 commits March 2, 2026 04:11
Fixes: record not found when refreshing detail page

Root cause: syncDriverIds() unconditionally set _id = id, overwriting
seed data's stable _id values with driver-generated timestamp-based ids.
On page refresh, the in-memory kernel reboots with new generated ids,
making old URL record ids invalid.

Changes:
- syncDriverIds now promotes seed _id to canonical id when present
- findOne $expand path handles array results defensively
- Added tests verifying stable seed ids and HTTP fetch by _id

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix refresh issue displaying record not found for opportunity detail fix: preserve seed data _id as stable record id across page refreshes Mar 2, 2026
@hotlong hotlong marked this pull request as ready for review March 2, 2026 04:42
Copilot AI review requested due to automatic review settings March 2, 2026 04:42
@hotlong hotlong merged commit da0b984 into main Mar 2, 2026
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes unstable record URLs in the console MSW/in-memory mock environment by ensuring seed _id values remain the canonical identifier across kernel reboots (page refresh), preventing “Record not found” deep-link failures.

Changes:

  • Update syncDriverIds() to promote explicit seed _idid (and otherwise derive _id from id) for stable identifiers across refreshes.
  • Make ObjectStackAdapter.findOne() with $expand robust to servers returning a flat array response.
  • Add MSW integration tests to verify stable seed IDs and HTTP fetch-by-id behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/console/src/mocks/createKernel.ts Adjusts seed record ID synchronization to preserve stable _id values across MSW kernel restarts.
packages/data-objectstack/src/index.ts Adds defensive handling for array-shaped responses in the $expand path of findOne().
apps/console/src/tests/MSWServer.test.tsx Adds integration coverage ensuring seed IDs are preserved and records are retrievable by stable ID over HTTP.

Comment on lines 296 to 297
const resultObj = result as { records?: T[]; value?: T[] };
const records = resultObj.records || resultObj.value || [];
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new array-response handling in the findOne() $expand path isn’t covered by existing adapter tests. Please add/extend a unit test (e.g. in src/expand.test.ts) where the raw fetch returns an unwrapped array (or { success: true, data: [...] }) to ensure findOne() returns the first record instead of null.

Suggested change
const resultObj = result as { records?: T[]; value?: T[] };
const records = resultObj.records || resultObj.value || [];
const resultObj = result as { records?: T[]; value?: T[]; data?: T[] };
const records = resultObj.records || resultObj.value || resultObj.data || [];

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants