You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c2bfa3e
Browse filesBrowse the repository at this point in the historyBrowse files
fix(app-shell): cited-section locator tells an unlisted same-titled heading from an undrawn one, and opens a heading that reads as nothing at once (#37646)
Fixes#37562
Clause-②: yes (widening)
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:使用应用内 AI
的用户,点回答里的“引自记录”引用条打开记录时,若正文里画出了与被引标题同名、但不在目录里的标题,页面立刻打开该字段而不再标记错的那一节;被引标题没有任何文字(只有符号)时,字段也立刻滚到,不再等四秒。
- 为什么做:记录 AI 问询专题里引用定位的两个边角,来自上一轮引用条跟进卡留下的范围说明;本轮按席位裁定,改为用字段自身的渲染解析来数标题。
- 出错会怎样:引用条打开记录时停在字段而不是标题;记录与对话数据不受影响,撤回本次合并即可恢复原样。
- 要你做什么:无。
## What changes
Governing text: scope note 7190147175 on #37487 (N6, N7); seat REWORK
7200445298 on this PR (S1 route ruling, N1, N3) over contract record
7200419777; claim amendment 7200539429 on #37562 (surface widened to
`ui/packages/fields`, option A of blocked report 7200523842).
**`ui/packages/fields`** (additive):
- `widgets/markdownHeadings.ts` (new): `MARKDOWN_REMARK_PLUGINS`
(remark-gfm) and `MARKDOWN_REHYPE_PLUGINS` (rehype-sanitize with
`RICH_TEXT_SANITIZE_SCHEMA`) are declared here once.
`drawnMarkdownHeadings(value)` runs react-markdown with those lists
(called as a function, it holds no hooks), reads the tree after the last
rehype plugin, and returns each drawn h1-h6 as `{ text, start }`.
`start` is the heading's source offset, and it is undefined for the
footnote section's `Footnotes` label, which the pipeline adds.
- `widgets/MarkdownContent.tsx`: draws with those same constants and
re-exports them with `drawnMarkdownHeadings`. Behaviour is unchanged:
the same plugin lists, now identity-stable.
- `index.tsx`: `loadDrawnMarkdownHeadings()` loads the reader through
`MarkdownContent.js`, the module the face already loads on demand. It
also exports the `DrawnMarkdownHeading` type.
- A first cut imported `markdownHeadings` from the index directly. That
made `MarkdownContent` both statically and dynamically imported, and
`Build & E2E UI` caught it as an INEFFECTIVE_DYNAMIC_IMPORT on head
6ef69f4.
- The final layout keeps exactly one lazy markdown module. Local console
build: the ineffective-import ledger reports all pinned, with none new.
**`ui/packages/app-shell/src/views/recordSectionAnchor.ts`**:
- **S1 / N1, the markdown half** now counts from the parse, not from
source lines. `unlisted` = drawn headings of the cited reading whose
`start` is not the start of a listed heading of that reading. So it
counts what the face draws by construction:
- setext headings in a quote or under a comment, a link definition or
indented code;
- footnote headings and the `Footnotes` label.
- Raw heading tags, indented code and a lazy quote over a rule no longer
count.
- The reader is loaded on demand (`loadSectionHeadingReader`, once; a
failed load is retried on the next call). A markdown candidate counted
before the load has `unlisted: undefined`, and its count is not trusted.
`focusRecordSection` loads the reader, re-counts and tries again. Until
then, no heading is marked.
- **HTML half**: unchanged.
- **N3**: `unlisted > 0` returns `fieldOnly` in `locateSection`'s first
condition (one line). The field is then scrolled to as soon as it is
drawn, not after the 4 s settle.
- **N6 / N7** as before: `counted = unlisted === 0 && drawn.length ===
count`, and an empty reading is `fieldOnly`. `mayScroll` is unchanged;
every scroll still goes through it.
- `RecordDetailView.citedSection-37365.test.tsx`: one comment updated
(the setext case now scrolls at once). No assertion changed.
## Tests
- `fields/src/__tests__/markdownHeadings-37562.test.tsx` (new). Every
shape is pinned twice: against the reader and against the face's own DOM
(`MarkdownContent` rendered).
- S1, drawn and answered: setext in a quote; setext under a comment
line; under a link definition; under indented code; footnote ATX plus
the `Footnotes` h2; ATX behind a quote or a list marker.
- N1, never drawn and not answered: a raw heading tag, an indented code
line, a lazy quote over a rule, fenced code.
- Also pinned: `start` offsets, the `Footnotes` label's undefined
`start`, and that the index loader resolves the same function.
- `app-shell/src/views/recordSectionAnchor.test.tsx`:
- S1: ten shape rows count `unlisted: 1`, plus the `Footnotes` label
against a cited `Footnotes` (CONTROL: no footnote, 0).
- N1: five rows count 0.
- The html rows are kept.
- A fresh-module case: before the parse loads the count is undefined and
no heading is marked; once it loads the heading is marked and scrolled
once. This case caught a real bug in the first cut.
- N3 with fake timers: a scroll at once. CONTROL: an undrawn titled
heading still waits for the settle.
- The N6 and N7 cases are kept.
- Ablation, parse-based count (`scripts/ablation-replace.mjs`, anchor `
return readDrawnMarkdown(value).filter(` -> ` return 0 *
readDrawnMarkdown(value).filter(`, blob c5fa5fb -> f483a359da34).
Result: Tests 14 failed | 25 passed, red on the N6 pair case, the old
setext case, all ten S1 rows, the `Footnotes` row and N3; the N1 rows
stay green as expected. Restored: blob == HEAD and `git diff HEAD`
empty.
- Earlier ablations (N6 count guard, N7 `fieldOnly`): see the first
round, unchanged code paths.
## Acceptance notes
- N2 (the outline reads source text, the page reads rendered text) is
not done here; the seat files it. The unlisted count compares starts per
reading, so a listed heading drawn under another reading counts as
unlisted. That closes the wrong-section half of N2 for this guard only,
not the mismatch itself.
- With the parse, the exact drawn index of the cited heading is now
knowable; marking it despite unlisted headings is possible. It is left
as the field, per N3.
- `MarkdownContent.tsx` gains two react-refresh `only-export-components`
warnings for the re-exported constants (warn level; the index already
carries many).
## Verification
Two-minute check: `cd ui && pnpm exec vitest run
packages/fields/src/__tests__/markdownHeadings-37562.test.tsx
packages/app-shell/src/views/recordSectionAnchor.test.tsx`. Expect all
passed.
Read first, in order:
1. `fields/src/widgets/markdownHeadings.ts` (the risk: a tree read that
differs from what is drawn).
2. `recordSectionAnchor.ts` `unlistedMarkdownCount` /
`withUnlistedCount` and the load path in `focusRecordSection`.
3. `fields/src/index.tsx` `loadDrawnMarkdownHeadings` (lazy-chunk
shape).
<details><summary>Readings, head c3f7728 (tree
objectstack-ai/objectstack)</summary>
- `vitest run` recordSectionAnchor.test.tsx +
RecordDetailView.citedSection-37365.test.tsx +
markdownHeadings-37562.test.tsx + markdownCellHeading-36344.test.tsx:
Test Files 4 passed (4), Tests 69 passed (69); lock VERDICT command-exit
0.
- Full `@object-ui/fields` suite (taken at 6ef69f4; the head commit
after it moves the plugin lists between two fields modules, and the four
files above were rerun on it): Test Files 333 passed | 1 skipped (334),
Tests 5085 passed | 7 skipped; VERDICT command-exit 0.
- Full `@object-ui/app-shell` suite: not run locally (2452 files, over
an hour on the shared lock last round). CI `Test UI` covers it: every
shard green on this head.
- `type-check` of `@object-ui/fields` and `@object-ui/app-shell` (both
programs each): VERDICT command-exit 0.
- Console `vite build`, local: ineffective-dynamic-import ledger: 40
ineffective dynamic imports, all pinned, none new. Eager closure
120/2610 chunks, 1992997 bytes gzipped. The same build on base b1c41e5
(fields and anchor sources restored from it) gives 120/2610 chunks,
1992700 bytes: +297 bytes, no new eager chunk. `vendor-react-markdown`
is eager on both. `pnpm check:eager-closure`: 1946.3 KB of 2431.6 KB
budget.
- `dispatch-gates --commands`: 39 derived (9 paths); 38 run on this head
plus `check:changeset-fixed`, all exit 0. `pnpm --dir ui exec vitest run
scripts/` (at 6ef69f4): 172 passed | 2 skipped. `--ran` verdict: 39
derived families accounted for, 39 run, 0 NOT-MEASURED.
- `overlap-check --branch=HEAD`: VERDICT clean exit 0.
- CI on c3f7728: 44 success / 13 skipped / 0 failure. Lint & Repo
Gates, TypeScript Type Check, Test Core, Governed Surface Queue Guard,
Lint UI, Type Check UI, Test UI (15 shard runs, all success), Build &
E2E UI, Live E2E UI, Dogfood Regression Gate, Check Changeset and Type
Check · debt ledger all succeeded; Build Core was skipped.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc)_
<!-- signed: repo:objectstack#5 · os-bill ·
session_01Utp6CbeF2saT6wUBV4E9uc -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
feat(fields): read the headings a markdown value's document face draws, from the face's own parse
6
+
7
+
Clause-②: yes (widening)
8
+
Metadata-protocol: none
9
+
10
+
`@object-ui/fields` exports `loadDrawnMarkdownHeadings()`, which loads on demand and answers `drawnMarkdownHeadings(value)`: each heading the markdown `document` face draws, with its text and where it starts in the value (none for the footnote section's `Footnotes` label, which the pipeline adds), and the `DrawnMarkdownHeading` type. It runs the face's own pipeline (react-markdown with the GitHub Flavored Markdown and sanitize plugins `MarkdownContent` draws with), so a reader that must agree with the drawn page counts what is drawn by construction, and react-markdown stays in the lazy chunk the face already lives in. The face draws exactly as before.
fix(app-shell): a record opened at a cited section no longer marks a same-titled heading the outline does not list, and opens its field at once when no heading can be told apart
6
+
7
+
Clause-②: no
8
+
Metadata-protocol: none
9
+
10
+
A record opened from a citation chip (`?section=ANCHOR`) finds the cited heading among the field's drawn headings that read the same, by count. When the body draws both a same-titled heading the outline does not list (a setext heading, one in a quote, a list item or a footnote, the footnote section's label) and a listed heading the face does not draw (one inside a raw HTML block), the two counts agreed while the index pointed at the wrong heading. A markdown body's unlisted headings are now counted from the field's own parse (`@object-ui/fields`' `loadDrawnMarkdownHeadings`, loaded on demand), so they are the headings the face draws; an html body's from its heading tags. When the body draws one, the field is opened instead of a heading that may be another section. That field, like the field of a cited heading with no letter or digit, is now scrolled to as soon as it is drawn instead of after the four-second settle; a titled heading that is not drawn yet still waits for it.
it('objectstack#37562 N6 — one unlisted same-titled heading plus one listed-but-undrawn heading opens the field, never a heading; CONTROL: the first Scope a paragraph line, the cited heading is marked',()=>{
144
+
// A setext `Scope` the outline does not list, and `# Scope` inside a raw
145
+
// HTML block that the outline lists and the face does not draw: the face
146
+
// draws two `Scope`s and the outline lists two, so the count agrees while
147
+
// index 0 of the drawn ones is the setext heading, not the cited one.
it('objectstack#37562 N7 — a heading that reads as nothing scrolls to the field at once; CONTROL: a titled heading not yet drawn still waits for the settle',()=>{
it('objectstack#37562 N3 — a body drawing a same-titled heading the outline does not list scrolls to the field at once; CONTROL: without it, an undrawn heading still waits for the settle',()=>{
0 commit comments