Skip to content

Run component inits with their arguments - #212

Draft
reeceyang wants to merge 2 commits into
mainfrom
ry/component-init
Draft

reeceyang wants to merge 2 commits into
mainfrom
ry/component-init

Conversation

@reeceyang

@reeceyang reeceyang commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Run each registered component's init, with the arguments its parent's convex.config passes, before the first call after the component is registered, so tests see the same initial state a push sets up. Inits run in one transaction with the backend's init restrictions: they can't call other functions or read environment variables, and they get the init limits on reads, writes, scheduling and file storage. Tests can override arguments with convexTest({ componentArgs }) or registerComponent(..., { args }), and rerun every init with t.runInits().

This needs convex/convex#62236 (draft), which makes init and args public and lets an imported component definition work outside the Convex runtime. Until that ships, the convex devDependency points at its pkg-pr-new preview.

🤖 Generated with Claude Code

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/convex-test@212

commit: 10c81df

reeceyang added a commit to convex/workpool that referenced this pull request Nov 19, 2026
reeceyang added a commit to convex/aggregate that referenced this pull request Nov 19, 2026
reeceyang added a commit to convex/resend that referenced this pull request Nov 19, 2026
reeceyang added a commit to convex/resend that referenced this pull request Nov 19, 2026
reeceyang added a commit to convex/workpool that referenced this pull request Nov 19, 2026
reeceyang added a commit to convex/aggregate that referenced this pull request Nov 19, 2026
reeceyang added a commit to convex/resend that referenced this pull request Nov 19, 2026
Also move the init test into example/convex so the root tsc doesn't pull in the example.
reeceyang added a commit to convex/workpool that referenced this pull request Nov 19, 2026
Also inline batch-worker in vitest, since convex-test now loads its convex.config, and pass a config to the enqueueHandler calls main added to loop.test.ts.
reeceyang added a commit to convex/resend that referenced this pull request Nov 19, 2026
Also move the init test into example/convex so the root tsc doesn't pull in the example, and type the test app's register callback so tsc can check it.
reeceyang added a commit to convex/workpool that referenced this pull request Nov 19, 2026
Also inline batch-worker in vitest, since convex-test now loads its convex.config, and pass a config to the enqueueHandler calls main added to loop.test.ts.
reeceyang added a commit to convex/resend that referenced this pull request Nov 19, 2026
Also move the init test into example/convex so the root tsc doesn't pull in the example, and type the test app's register callback so tsc can check it.
reeceyang added a commit to convex/workpool that referenced this pull request Nov 19, 2026
Also inline batch-worker in vitest, since convex-test now loads its convex.config, and pass a config to the enqueueHandler calls main added to loop.test.ts.
reeceyang added a commit to convex/resend that referenced this pull request Nov 19, 2026
Also move the init test into example/convex so the root tsc doesn't pull in the example, and type the test app's register callback so tsc can check it.
reeceyang added a commit to convex/resend that referenced this pull request Nov 19, 2026
Also move the init test into example/convex so the root tsc doesn't pull in the example, and type the test app's register callback so tsc can check it.
reeceyang added a commit to convex/workpool that referenced this pull request Nov 19, 2026
Also inline batch-worker in vitest, since convex-test now loads its convex.config, and pass a config to the enqueueHandler calls main added to loop.test.ts.
reeceyang and others added 2 commits November 20, 2026 16:40
Run each registered component's init before the next function call, the way a
push does: one transaction, each init nested in it with the backend's init
limits, every init run even when one fails, and an error listing each failure
that rolls back all of them. `t.runInits()` runs every init again.

An init's arguments come from the parent's `convex.config` (`use(child, { args })`),
or from `componentArgs` / `registerComponent(..., { args })`. They're resolved
like the backend resolves them: function references become handles to the
parent's functions, child components become objects of handles to their public
functions, and `component.args.<name>` forwards the parent's own argument.

Inits can't read environment variables, call other functions, or use file
storage, as in the runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The init fixtures need component.args and the use() fix, which aren't in a
convex release yet. The preview also makes the init and args types public, so
the fixtures drop their casts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant