Skip to content

fix: preserve Nitro workflow step registration side effects#1386

Merged
VaguelySerious merged 4 commits intovercel:mainfrom
comfuture:fix/nitro-step-side-effects
Apr 1, 2026
Merged

fix: preserve Nitro workflow step registration side effects#1386
VaguelySerious merged 4 commits intovercel:mainfrom
comfuture:fix/nitro-step-side-effects

Conversation

@comfuture
Copy link
Copy Markdown
Contributor

Summary

  • side-effect import generated Nitro workflow handler bundles before reading their POST export
  • keep step registration side effects alive when Nitro bundles workflow/steps.mjs
  • add a regression test for Nitro v2 and v3 virtual handlers

Why

In Nitro/Nuxt local production builds, the generated workflow/steps.mjs bundle can be treated as a pure export provider when the virtual handler only imports { POST }. That allows the step bundle's top-level registerStepFunction(...) calls to disappear from the final Nitro server bundle, which leads to runtime failures like Step \"...\" not found when a queued step executes.

Importing the generated bundle for side effects before consuming POST keeps the registration code in the final server output.

Validation

  • pnpm vitest run packages/nitro/src/index.test.ts
  • pnpm --filter @workflow/example-nuxt build
  • confirmed the built Nuxt Nitro bundle contains registerStepFunction(...) calls for app steps after this change

@comfuture comfuture requested a review from a team as a code owner March 14, 2026 04:52
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 14, 2026

🦋 Changeset detected

Latest commit: a536418

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
@workflow/nitro Patch
@workflow/nuxt Patch
workflow Patch
@workflow/ai Patch
@workflow/world-testing Patch
@workflow/core Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/vitest Patch
@workflow/web-shared Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 14, 2026

@comfuture is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@pranaygp
Copy link
Copy Markdown
Collaborator

@VaguelySerious @pi0 what do you think?

@pranaygp pranaygp requested review from VaguelySerious and pi0 March 15, 2026 23:44
@pi0
Copy link
Copy Markdown
Collaborator

pi0 commented Mar 16, 2026

LGTM if it is delibrate to even have side effects... Is there any backstory to this? (why we need side-effects?)

@VaguelySerious
Copy link
Copy Markdown
Member

Hey @comfuture, could you ensure this check passes? And also add a comment as to what issue you were seeing concretely that was solved through this PR. Once that's done, we'll run e2e tests and merge the PR

Signed-off-by: comfuture <comfuture@gmail.com>
Signed-off-by: comfuture <comfuture@gmail.com>
Signed-off-by: comfuture <comfuture@gmail.com>
@comfuture comfuture force-pushed the fix/nitro-step-side-effects branch from 2d6de62 to 04ac256 Compare March 27, 2026 08:28
@comfuture
Copy link
Copy Markdown
Contributor Author

Hey @comfuture, could you ensure this check passes? And also add a comment as to what issue you were seeing concretely that was solved through this PR. Once that's done, we'll run e2e tests and merge the PR

Thanks. I fixed the check that was failing there; it was the DCO check, and it now passes.
The concrete issue I was seeing was in Nuxt + Nitro production builds when @workflow/nuxt was enabled.

In that setup, the generated workflow/steps.mjs module could be reduced to only importing POST, which meant the handler itself loaded, but the module’s top-level step registrations did not run. As a result, the app built successfully, but the workflow steps were missing at runtime after build.

This change keeps a bare import of the generated steps module so those registration side effects are preserved.

@pi0
Copy link
Copy Markdown
Collaborator

pi0 commented Apr 1, 2026

Just a note, next nitro v3 release will have less agressive tree-shaking config (currently available in nightly) worth to check if after we still need this fix or not. More info: nitrojs/nitro#4164

@VaguelySerious VaguelySerious merged commit 0e8a880 into vercel:main Apr 1, 2026
16 of 92 checks passed
@VaguelySerious
Copy link
Copy Markdown
Member

@pi0 Merged for now and will add a comment mentioning that this fix could maybe be reverted after nitrojs/nitro#4164

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.

4 participants