Skip to content

Backport #1944: [swc-plugin] Preserve imports referenced by hoisted nested steps#1946

Open
github-actions[bot] wants to merge 1 commit intostablefrom
backport/pr-1944-to-stable
Open

Backport #1944: [swc-plugin] Preserve imports referenced by hoisted nested steps#1946
github-actions[bot] wants to merge 1 commit intostablefrom
backport/pr-1944-to-stable

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 5, 2026

Automated backport of #1944 to stable.

AI recommendation: This commit fixes three runtime bugs in the SWC plugin (dropped imports referenced by hoisted nested steps, mismatched step IDs for non-exported workflow shapes, and incorrect manifest step IDs) that affect existing functionality likely present on stable. The fix is self-contained to the SWC plugin transform with regression fixtures and does not depend on any main-only APIs, making it a good candidate for backport.

Merge conflicts were resolved by AI (opencode with anthropic/claude-opus-4.7). Please review the conflict resolution carefully before merging.

* [swc-plugin] Preserve imports referenced by hoisted nested steps

Dead-code elimination ran before nested step functions were hoisted out of workflow bodies, so imports referenced only by hoisted step bodies were incorrectly stripped from the step bundle, causing a ReferenceError at runtime. Move DCE to run after hoisting in visit_mut_program.

* [swc-plugin] Namespace nested step IDs under non-exported workflow functions

Anonymous steps nested inside callback properties of a non-exported workflow function were registered with an unnamespaced step ID in step mode while the workflow-mode proxy looked them up under the workflow function name, causing a runtime 'step not found' failure. Set current_workflow_function_name in visit_mut_fn_decl for non-exported workflow functions to match the behavior in visit_mut_export_decl. Also clarify the fixture comment to distinguish step-mode and workflow-mode behavior per reviewer feedback.

* [swc-plugin] Namespace nested step IDs across all workflow declaration shapes

Extends the previous fix to cover all three non-exported workflow declaration forms (async function decl, const arrow, const fn-expr) by visiting the workflow body with workflow context before replacing it, and corrects the __internal_workflows manifest comment to report the same prefixed step IDs that are registered at runtime and looked up by the workflow-mode WORKFLOW_USE_STEP proxy. Adds a dedicated regression fixture covering all three shapes.

Signed-off-by: Nathan Rajlich <n@n8.io>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

🦋 Changeset detected

Latest commit: 0cbd515

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

This PR includes changesets to release 19 packages
Name Type
@workflow/swc-plugin Patch
@workflow/astro Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/nest Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
tarballs Patch
workflow Patch
@workflow/vite Patch
@workflow/vitest Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/ai Patch
@workflow/core Patch
@workflow/web-shared Patch
@workflow/web 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 May 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview, Comment May 5, 2026 9:57pm
example-nextjs-workflow-webpack Ready Ready Preview, Comment May 5, 2026 9:57pm
example-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-astro-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-express-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-fastify-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-hono-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-nitro-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-nuxt-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-sveltekit-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-tanstack-start-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workbench-vite-workflow Ready Ready Preview, Comment May 5, 2026 9:57pm
workflow-docs Ready Ready Preview, Comment, Open in v0 May 5, 2026 9:57pm
workflow-swc-playground Ready Ready Preview, Comment May 5, 2026 9:57pm
workflow-tarballs Ready Ready Preview, Comment May 5, 2026 9:57pm
workflow-web Ready Ready Preview, Comment May 5, 2026 9:57pm

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.

0 participants