Skip to content

Commit efd710a

Browse files
test(schema-catalog): the gallery waits for a lazy tile to paint before reading its authored content (#35441)
Fixes #35407 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:组件目录画廊测试在检查看板和 Markdown 两类示例时,先确保它们延迟加载的真实内容已经出现,再判断内容是否上屏;断言本身一条未改、未放宽、未跳过。 - 为什么改:这个测试有时读到的是加载中的占位骨架而不是真实内容,于是时红时绿,把改到表格插件等相关包的 PR 从合并队列里踢出去(#35371 三次里红了两次)。 - 风险与回滚:只改一个测试文件,不动任何产品代码,用户无感;回滚即撤销本 PR。 - 先看:`ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx` 顶部新增的两行模块预加载,以及 `renderEntry` 开头新增的一次 `act` 让步。 - 两分钟验证:`pnpm --dir ui exec vitest run examples/schema-catalog/test/catalog-gallery-render.test.tsx -t "puts its authored content on screen"`,预期 19 个用例全绿(修复前稳定 5 个红)。 - 需要你做的:无,席位落地。 ## What changes One test file, `ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx`; no product source. 1. **Module-scope loads of the two lazy implementation modules**, per the ui/AGENTS.md lazy-boundary rule: `../../../packages/plugin-kanban/src/KanbanImpl` and `../../../packages/plugin-markdown/src/MarkdownImpl`, with a one-line comment. 2. **`await act(async () => {})` at the start of `renderEntry`**, before the existing settles. Why both: `renderEntry`'s settle waits for `drewSomething`, and a Suspense Skeleton fallback (an element, no text) satisfies it. The preload alone was measured NOT to be enough: with it, the isolated run still failed 2 of 5 — the first-rendered kanban and markdown tile. `React.lazy` still suspends on its first render even when the module is loaded, because `import()` settles a tick later and the settle returns on the fallback before that tick. The `act` yield lets that tick reach the screen; it is only sufficient because the module is already loaded, which is what (1) guarantees. Both halves were ablated (below) and each is necessary. **Same modules as the components' `import()`** — two proofs: - Path: the vitest alias table maps `@object-ui/plugin-kanban` to `ui/packages/plugin-kanban/src` and `@object-ui/plugin-markdown` to `ui/packages/plugin-markdown/src`. `KanbanBoardCore.tsx` there holds `React.lazy(() => import('./KanbanImpl'))`, and plugin-markdown's `index.tsx` holds `React.lazy(() => import('./MarkdownImpl'))`. Resolving the test's specifiers and the lazy targets gives the same realpath for each pair (`same= true` for kanban and markdown). - Behaviour: removing only the preload turns the isolated run back to 5 failed. A preload of a different module instance could not have turned it green. No changeset: `@object-ui/example-schema-catalog` is `private: true` and the diff is a test file, so nothing publishes (`skip-changeset`). ## Tests No assertion added, removed or loosened. The pins are the existing `puts its authored content on screen` cases. ## Acceptance notes - The order named route A (preload only). Preload alone was measured insufficient, so the fix adds the `act` yield inside the same file. Both halves are ablation-proven. ## Verification <details><summary>Before / after — isolated run red 5 to green, whole file 579/579</summary> - Before, at base `3f88af4c`: `pnpm --dir ui exec vitest run --maxWorkers=2 examples/schema-catalog/test/catalog-gallery-render.test.tsx -t "puts its authored content on screen"` gave `Tests 5 failed | 14 passed | 560 skipped (579)`. The 5 were kanban advanced-with-badges and basic-board, and markdown advanced-features, basic and tables. - Preload only, at `56183817`: same command gave `Tests 2 failed | 17 passed | 560 skipped`, the first kanban and the first markdown tile. - After, at `e605f090`: same command gave `Tests 19 passed | 560 skipped (579)`, lock VERDICT command-exit 0. - After, whole file at `e605f090`: `Test Files 1 passed (1)`, `Tests 579 passed (579)`. - After, whole package (`examples/schema-catalog/`): `Test Files 45 passed (45)`, `Tests 2438 passed (2438)`. - `pnpm --filter @object-ui/example-schema-catalog run type-check` (`tsc -p tsconfig.test.json` included): exit 0. </details> <details><summary>Ablation — each half removed alone turns the isolated run red</summary> Through `scripts/ablation-replace.mjs`; every leg was restored to the HEAD blob `a06cdce606ec` with `git diff HEAD` empty. - Preload lines deleted: blob became `f2aada8cbe58` and the run gave `Tests 5 failed | 14 passed | 560 skipped`. - `act` yield deleted: blob became `ca339620f405` and the run gave `Tests 2 failed | 17 passed | 560 skipped`. </details> <details><summary>Gates: 22 of 22 derived families exit 0 at e605f09</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 22 commands for 1 path, against merge base `3f88af4c9`. All 22 exited 0, with each exit code captured before any pipe. They include `check:cross-package-test-inputs`, `check:test-source-alias`, `check:undeclared-dep-imports`, `check:nul-bytes`, `check:type-check-coverage` and `check:type-check-debt`. The `--ran` reconciliation reads `22 derived famil(ies) accounted for, 22 run, 0 NOT-MEASURED`. Two more local checks: ui `check:new-line-citations` exited 0, and eslint on the changed file exited 0. CI owns Test UI and the type-check lanes. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CZrgaiMgTJCnswR6jQ)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9fea316 commit efd710a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎ui/examples/schema-catalog/test/catalog-gallery-render.test.tsx‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
* assertion is correct for a dashboard tile and wrong for the corpus.
133133
*/
134134
import { describe, it, expect, vi, beforeEach, afterEach, afterAll } from 'vitest';
135-
import { render, waitFor, cleanup } from '@testing-library/react';
135+
import { render, waitFor, cleanup, act } from '@testing-library/react';
136136
import '@object-ui/components';
137137
// Mirrors the docs-site gallery host's registration list, in its order. The host
138138
// (`registerCatalogBlocks.ts`) was deleted with the site by objectstack#27145;
@@ -150,6 +150,9 @@ import '@object-ui/plugin-timeline';
150150
import '@object-ui/plugin-view';
151151
import '@object-ui/plugin-form';
152152
import '@object-ui/plugin-grid';
153+
// ui/AGENTS.md lazy-boundary rule: the modules kanban's and markdown's React.lazy import() loads, so a tile never asserts on its Suspense fallback (objectstack#35407).
154+
import '../../../packages/plugin-kanban/src/KanbanImpl';
155+
import '../../../packages/plugin-markdown/src/MarkdownImpl';
153156
import { SidebarProvider } from '@object-ui/components';
154157
import { registerLayout } from '@object-ui/layout';
155158
import { ComponentRegistry } from '@object-ui/core';
@@ -462,6 +465,11 @@ async function renderEntry(schema: unknown): Promise<Rendered> {
462465
</SidebarProvider>
463466
</SchemaRendererContext.Provider>,
464467
);
468+
// A `React.lazy` tile paints its Suspense fallback first even when its module
469+
// is already loaded (the module-scope imports above): `import()` settles a tick
470+
// later. Let that tick reach the screen before the settles below, which the
471+
// fallback alone would satisfy (objectstack#35407).
472+
await act(async () => {});
465473
// Two settles, for two different asynchronous shapes:
466474
// - a dataset widget starts in `loading` and resolves on a promise;
467475
// - `code-editor`, `kanban` and `markdown` are `React.lazy` behind

0 commit comments

Comments
 (0)