Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

Files without "use workflow" or "use step" directives were failing SSR with ReferenceError: React is not defined. The loader was preventing Next.js from applying automatic JSX runtime transforms.

Changes

packages/next/src/loader.ts

  • Use webpack callback API for pass-through instead of returning raw source
  • When no directive found: callback(null, source, sourceMap) → allows Next.js SWC to process file
  • Previously: return normalizedSource → blocked subsequent loaders

packages/next/src/index.ts

  • Remove Turbopack rule configuration that overrode Next.js's built-in JSX handling
  • Custom *.tsx/*.ts rules replaced default transforms, breaking files without directives

Why

In webpack, returning source from a loader marks the file as processed, skipping remaining loaders. In Turbopack, defining custom rules for file extensions replaces default handling entirely. Both prevented Next.js's automatic JSX transform (react/jsx-runtime) from running.

// Before: blocked Next.js transforms
if (!normalizedSource.match(/(use step|use workflow)/)) {
  return normalizedSource;
}

// After: passes through to Next.js loaders
if (!normalizedSource.match(/(use step|use workflow)/)) {
  return callback(null, source, sourceMap);
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fonts.googleapis.com
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/workflow/workflow/node_modules/.pnpm/next@15.5.4_@opentelemetry+api@1.9.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/dist/compiled/jest-worker/processChild.js (dns block)
    • Triggering command: node /home/REDACTED/work/workflow/workflow/workbench/nextjs-turbopack/node_modules/.bin/../next/dist/bin/next build --turbopack (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>@workflow/next loader breaks automatic JSX transform (React is not defined during SSR)</issue_title>
<issue_description>After enabling Workflow in next.config.mjs:

import { withWorkflow } from '@workflow/next';
export default withWorkflow({ reactStrictMode: true });

some .tsx files without "use workflow" or "use step" fail during SSR with:

ReferenceError: React is not defined

The generated server bundle contains React.createElement(...) but no import React, meaning the automatic JSX transform isn’t applied.

Findings

  • The loader (@workflow/next/dist/loader.js) short-circuits by returning the raw source when no directive is found.
  • Because it runs before Next’s SWC, those files skip the automatic JSX transform and fall back to the classic runtime.
  • On branches without the Workflow wrapper, everything renders normally.

Expected
Files without Workflow directives should still use Next’s automatic JSX transform (react/jsx-runtime) and not require a React import.

Environment

  • Next.js 16.0.1
  • React 19
  • @workflow/next 4.0.1-beta.6
  • Node 22

Disclaimer: We are newcomers and this issue analysis was created using AI. Really sorry if this is not the correct way or place to open this issue.
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@changeset-bot
Copy link

changeset-bot bot commented Nov 7, 2025

⚠️ No Changeset found

Latest commit: 9af3ebf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link
Contributor

vercel bot commented Nov 7, 2025

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

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Nov 7, 2025 8:37am
example-nextjs-workflow-webpack Ready Ready Preview Comment Nov 7, 2025 8:37am
example-workflow Ready Ready Preview Comment Nov 7, 2025 8:37am
workbench-nitro-workflow Ready Ready Preview Comment Nov 7, 2025 8:37am
workbench-nuxt-workflow Ready Ready Preview Comment Nov 7, 2025 8:37am
workbench-sveltekit-workflow Ready Ready Preview Comment Nov 7, 2025 8:37am
workbench-vite-workflow Ready Ready Preview Comment Nov 7, 2025 8:37am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
workflow-docs Skipped Skipped Nov 7, 2025 8:37am

Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.com>
Co-authored-by: pranaygp <1797812+pranaygp@users.noreply.github.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.

@workflow/next loader breaks automatic JSX transform (React is not defined during SSR)

2 participants