Repository navigation
Commit eda55b9
fix(app-shell): a full-page record form opened by direct URL returns inside the app after save or cancel (#27558)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4Uu76CdcjMmgYPLs3UuMF1RMq)_
## 维护者速读
- 改了什么:整页记录表单(新建 /
编辑)保存或取消后,只有当本控制台会话里确有上一页时才"后退",否则进入记录详情(编辑)或对象列表(新建)。
- 为什么改:从粘贴链接、新标签页或深链打开表单时,原来按浏览器标签页的历史长度判断,会退出应用跳到控制台首页,保存提示也随旧页面一起丢失。
- 风险与回滚:只改 `RecordFormPage` 的返回判定一处;应用内进入的行为不变。回滚即还原该文件一个提交。
- 先看:`ui/packages/app-shell/src/views/RecordFormPage.tsx` 的
`goBack`(`hasInAppHistory`),然后看新测试
`RecordFormPage.directUrlReturn-27454.test.tsx`。
- 两分钟验证:在新标签页直接打开
`/_console/apps/com.example.showcase/showcase_task/new`,填写并点 Create,应看到
`Task "TITLE" created` 提示并停留在任务列表(应用内)。
- 需要你做的:无,席位落地。
Fixes #27454
Clause-②: no
Metadata-protocol: none
## What changes
- `RecordFormPage`'s `goBack` decided "came from inside the app" from
`window.history.length > 1`. That counts the tab's entries from before
the console document loaded, so a form opened by pasted URL, new tab or
deep link went Back out of the app, and the save toast fired just before
the document unloaded.
- It now reads react-router's own location key: the entry the router
started on is keyed `'default'`, every entry it navigated to gets a
generated key. Back only when the key is not `'default'`; otherwise the
existing parent route (record detail in edit mode, object list in create
mode) with `replace`. This is the same rule `FormPage`'s cancel already
uses in the console, and the same route in-app entry takes when nothing
is behind it, not a second fallback.
- Save and cancel share `goBack`, so both follow the rule; edit mode
(`/record/ID/edit`) is covered by the same change.
## Tests
New `RecordFormPage.directUrlReturn-27454.test.tsx`, with
`window.history.length` stubbed to 3 on every cell:
- edit, direct URL: save toasts `Task "Quarterly review" updated` and
lands on the record detail;
- create, direct URL: save toasts `Task "Quarterly review" created` and
lands on the object list;
- edit, direct URL: cancel lands on the record detail, no toast;
- edit and create, in-app entry (an earlier router entry): save and
cancel go back to that page.
Ablation (one-shot, through `scripts/ablation-replace.mjs`, restored to
the HEAD blob): putting the `window.history.length > 1` test back turns
the three direct-URL cells red and leaves the two in-app cells green, as
predicted.
## Acceptance notes
- `ui/packages/layout/src/PageHeader.tsx` (its back button) uses the
same `window.history.length > 1` pattern. That is the back-button
control, a different bug class from the after-save route; left unchanged
here.
## Verification
All readings on head `6912ecba`.
<details><summary>Local runs</summary>
- `pnpm --dir ui exec vitest run
packages/app-shell/src/views/RecordFormPage` (lock VERDICT command-exit
0): Test Files 10 passed, Tests 61 passed.
- Ablation run (lock VERDICT command-exit 1, expected): 3 failed, 2
passed; restore blob equals HEAD, `git diff HEAD` empty.
- `pnpm --filter @object-ui/app-shell run type-check` (both the source
and the test tsconfig): exit 0.
- `pnpm --dir ui check:new-line-citations`: 0 new citations, exit 0.
- `dispatch-gates --commands` derived 34 families; all 34 run with exit
0 recorded, `--ran` reconciliation: 34 run, 0 NOT-MEASURED, 0 UNRUN.
That includes `pnpm --dir ui exec vitest run scripts/` (169 files
passed, 2 skipped).
- Changed lines: 149 (+138 / -11) over 3 files.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L6bhgXU26UBEjd1KKHgNEx)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01L6bhgXU26UBEjd1KKHgNEx
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 49896f7 commit eda55b9
3 files changed
Lines changed: 138 additions & 11 deletions
File tree
- .changeset
- ui/packages/app-shell/src/views
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
127 | 131 | | |
| 132 | + | |
128 | 133 | | |
129 | | - | |
| 134 | + | |
130 | 135 | | |
131 | 136 | | |
132 | 137 | | |
133 | 138 | | |
134 | | - | |
| 139 | + | |
135 | 140 | | |
136 | 141 | | |
137 | 142 | | |
| |||
0 commit comments