@devries-cameron20 / t3code-1 / commits / 6ab39ff6b8
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

test(web): require-disposable-render is now an error (#22410)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 20, 2026 at 11:12 UTC 6ab39ff6b8f60447c2580b818351fe4387fffa82
4 files changed +68 -5
AGENTS.md
+6 -1
@@ -100,7 +100,12 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
100 - **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.
101 - Backend behavior changes ship with focused tests for that behavior.
102 - The server is event-sourced, and side effects run after the command commits. In tests, drain the effect worker (`OrchestrationEffectWorkerV2.drain`) or await the specific persisted event or `Deferred` that marks the milestone. Never wait on sleeps or polling. A test that needs a timeout to pass is wrong.
103 -- Web component tests are `*.browser.test.tsx` and render through `apps/web/test/render.tsx`. Acquire everything a test changes with `using`/`await using` so disposal undoes it even when the test fails; no `beforeEach`/`afterEach`, no module-level screens. Shared mock state that `vi.mock` factories read gets reset by a `setup()` call at the top of the test. `t3code/require-disposable-render` flags the old patterns.
103 +- Web browser tests are `*.browser.test.tsx` or `*.browser.test.ts` and render with `await using screen = await render(...)` from `apps/web/test/render.tsx`. `t3code/require-disposable-render` errors on the old patterns.
104 + - Acquire what the test drives after mounting (fake timers it advances, spies it sets up after mounting) after the render, so it disposes before the unmount. Anything the first render reads comes before it.
105 + - A helper that renders and then waits or clicks puts the screen in an `AsyncDisposableStack` and `move()`s it out only on success, so a failed wait still unmounts.
106 + - `rerender` needs a fresh element on every call.
107 + - No lifecycle hooks and no module-level mutable state. Shared mock state that `vi.mock` factories read is reset by a `setup()` call at the top of the test.
108 + - `router` is on by default. Pass `router: false` only with a one-line comment saying why.
109
110 ```tsx
111 it("saves on Enter", async () => {
oxlint-plugin-t3code/rules/require-disposable-render.test.ts
+22 -1
@@ -1,4 +1,4 @@
1 -import { describe } from "@effect/vitest";
1 +import { assert, describe } from "@effect/vitest";
2
3 import { createOxlintRuleHarness } from "../test/utils.ts";
4
@@ -18,6 +18,7 @@ describe("t3code/require-disposable-render", () => {
18 'it("renders", async () => {',
19 " await using screen = await render(null);",
20 " await act(() => screen.rerender(null));",
21 + ' await userEvent.click(screen.getByRole("button"));',
22 "});",
23 ].join("\n"),
24 );
@@ -39,8 +40,28 @@ describe("t3code/require-disposable-render", () => {
40 "rejects stubbing the act environment",
41 'vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);',
42 );
43 + browserTest.invalid(
44 + "rejects userEvent wrapped in act from react",
45 + [
46 + 'import { act } from "react";',
47 + 'it("clicks", async () => {',
48 + " await act(async () => {",
49 + " await userEvent.click(document.body);",
50 + " });",
51 + "});",
52 + ].join("\n"),
53 + (output) => assert.match(output, /Do not wrap userEvent in React's act/),
54 + );
55 + browserTest.invalid(
56 + "rejects importing lifecycle hooks from the test runner",
57 + 'import { beforeEach, it } from "vite-plus/test";',
58 + );
59 browserTest.invalid("rejects afterEach", "afterEach(async () => {});");
60 browserTest.invalid("rejects beforeAll", "beforeAll(() => {});");
61 unitTest.valid("allows lifecycle hooks outside browser tests", "beforeEach(() => {});");
62 + unitTest.valid(
63 + "allows importing lifecycle hooks outside browser tests",
64 + 'import { afterEach } from "vite-plus/test";',
65 + );
66 unitTest.invalid("still rejects react-dom/client in unit tests", 'import "react-dom/client";');
67 });
oxlint-plugin-t3code/rules/require-disposable-render.ts
+39
@@ -5,6 +5,7 @@ import { getPropertyName, unwrapExpression } from "../utils.ts";
5
6 const BROWSER_TEST_FILE = /\.browser\.test\.[cm]?[jt]sx?$/u;
7 const LIFECYCLE_HOOKS = new Set(["afterAll", "afterEach", "beforeAll", "beforeEach"]);
8 +const TEST_RUNNERS = new Set(["@effect/vitest", "vite-plus/test", "vitest"]);
9 const REACT_ACT_EXPORTS = new Set(["act", "unstable_act"]);
10 const ACT_ENVIRONMENT = "IS_REACT_ACT_ENVIRONMENT";
11 const HELPER = "Render with `await using screen = await render(...)` from apps/web/test/render.tsx";
@@ -13,6 +14,8 @@ const MESSAGES = {
14 reactDomClient: `${HELPER}; it owns the React root and unmounts it on dispose.`,
15 reactAct: `${HELPER} and import \`act\` from there; it enables React's act environment only while act runs.`,
16 actEnvironment: `${HELPER}; its act() sets ${ACT_ENVIRONMENT} for exactly as long as it runs.`,
17 + actAroundUserEvent:
18 + "Do not wrap userEvent in React's act; real input is not an act scope. Await the userEvent call directly.",
19 lifecycleHook:
20 "Browser tests acquire what they need with `using`/`await using` instead of lifecycle hooks, so nothing outlives the test that created it.",
21 };
@@ -41,9 +44,36 @@ export default defineRule({
44 },
45 create(context) {
46 const isBrowserTest = BROWSER_TEST_FILE.test(context.filename);
47 + const reactActNames = new Set<string>();
48 +
49 + const isInsideReactAct = (node: ESTree.Node) => {
50 + for (let current = node.parent; current; current = current.parent) {
51 + if (
52 + current.type === "CallExpression" &&
53 + current.callee.type === "Identifier" &&
54 + reactActNames.has(current.callee.name)
55 + ) {
56 + return true;
57 + }
58 + }
59 + return false;
60 + };
61
62 return {
63 ImportDeclaration(node) {
64 + if (isBrowserTest && TEST_RUNNERS.has(node.source.value)) {
65 + for (const specifier of node.specifiers) {
66 + if (specifier.type !== "ImportSpecifier") continue;
67 + const imported =
68 + specifier.imported.type === "Identifier"
69 + ? specifier.imported.name
70 + : specifier.imported.value;
71 + if (LIFECYCLE_HOOKS.has(imported)) {
72 + context.report({ node: specifier, message: MESSAGES.lifecycleHook });
73 + }
74 + }
75 + return;
76 + }
77 if (node.source.value === "react-dom/client") {
78 context.report({ node: node.source, message: MESSAGES.reactDomClient });
79 return;
@@ -56,6 +86,7 @@ export default defineRule({
86 ? specifier.imported.name
87 : specifier.imported.value;
88 if (REACT_ACT_EXPORTS.has(imported)) {
89 + reactActNames.add(specifier.local.name);
90 context.report({ node: specifier, message: MESSAGES.reactAct });
91 }
92 }
@@ -71,6 +102,14 @@ export default defineRule({
102 if (callee.value.type === "MemberExpression") {
103 // vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true) leaves the flag on for the whole test.
104 const method = getPropertyName(callee.value.property);
105 + if (
106 + callee.value.object.type === "Identifier" &&
107 + callee.value.object.name === "userEvent" &&
108 + isInsideReactAct(node)
109 + ) {
110 + context.report({ node, message: MESSAGES.actAroundUserEvent });
111 + return;
112 + }
113 if (
114 Option.getOrUndefined(method) === "stubGlobal" &&
115 stringValue(node.arguments[0] as ESTree.Node | undefined) === ACT_ENVIRONMENT
vite.config.ts
+1 -3
@@ -188,10 +188,8 @@ export default defineConfig({
188 rules: { "t3code/prefer-effect-fn": "off" },
189 },
190 {
191 - // Warns while the remaining web component tests move to apps/web/test/render.tsx.
192 - // Raise to "error" once `vp lint` reports no t3code(require-disposable-render) warnings.
191 files: ["apps/web/**/*.test.tsx"],
194 - rules: { "t3code/require-disposable-render": "warn" },
192 + rules: { "t3code/require-disposable-render": "error" },
193 },
194 {
195 files: ["apps/**/src/**", "packages/**/src/**"],