fix: preserve seed data _id as stable record id across page refreshes#950
fix: preserve seed data _id as stable record id across page refreshes#950
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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>
There was a problem hiding this comment.
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_id→id(and otherwise derive_idfromid) for stable identifiers across refreshes. - Make
ObjectStackAdapter.findOne()with$expandrobust 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. |
| const resultObj = result as { records?: T[]; value?: T[] }; | ||
| const records = resultObj.records || resultObj.value || []; |
There was a problem hiding this comment.
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.
| 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 || []; |
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-generatedid(e.g."opportunity-1772422975850-6"). On refresh, a new kernel generates different timestamps → old URL IDs are orphaned.Changes
apps/console/src/mocks/createKernel.ts—syncDriverIdsnow promotes explicit seed_idtoid, keeping record identifiers stable across kernel rebootspackages/data-objectstack/src/index.ts— Defensive array handling infindOne$expand path, consistent withnormalizeQueryResultforfind()apps/console/src/__tests__/MSWServer.test.tsx— Tests verifying seed IDs are preserved and records are fetchable by stable_idvia HTTPOriginal prompt
💡 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.