Skip to content

feat(react): use SSR transform of React Compiler for server envs - #1438

Draft
sapphi-red wants to merge 1 commit into
mainfrom
feat/react-use-ssr-transform-of-react-compiler-for-server-environment
Draft

feat(react): use SSR transform of React Compiler for server envs#1438
sapphi-red wants to merge 1 commit into
mainfrom
feat/react-use-ssr-transform-of-react-compiler-for-server-environment

Conversation

@sapphi-red

Copy link
Copy Markdown
Member

Description

Set outputMode=ssr option in React Compiler for server environments.

This has two problems:

  • The outputMode=ssr is probably not meant to be public yet. It's not released in babel one (react/react@4cf770d, react/react@50e7ec8)
  • consumer=server does not necessarily mean SSR. It may be an environment for RSC.

I found the option so I thought to fix it but found the problems above so I'm opening this PR as draft to discuss about these problems.

Comment on lines +96 to +97
expect(output.code).toContain('const count = 0')
expect(output.code).not.toContain('useState(0)')

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output looks like

import { jsxs as _jsxs } from "react/jsx-runtime";
export function App(t0) {
	const { name } = t0;
	const count = 0;
	return /* @__PURE__ */ _jsxs("div", { children: [name, count] });
}

@hi-ogawa

hi-ogawa commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Next has something similar and the one in the react compiler isn't likely directly usable (as in it may not be "production ready" for some edge cases).

The agents dug up some history:

Currently it:

  • Removes production-server useEffect and useLayoutEffect calls when dependencies have no observable side effects.
  • Does not optimize useState, although that implementation remains behind optimize_use_state: false.
  • Is enabled by default for production webpack server builds.
  • Is not currently wired into Turbopack because its server transform rule is commented out.

@hi-ogawa

Copy link
Copy Markdown
Contributor

consumer=server does not necessarily mean SSR. It may be an environment for RSC.

In rsc environment, useState/useEffect/etc is a runtime error since they are undefined in react-server exports, so the transform would ideally surfaces the usage error during build time instead like https://nextjs.org/docs/messages/react-client-hook-in-server-component. Rsc plugin currently doesn't do anything (yet).

expect(output.code).toContain('react/jsx-runtime')
expect(output.code).not.toContain('react/compiler-runtime')
expect(output.code).toContain('const count = 0')
expect(output.code).not.toContain('useState(0)')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(output.code).not.toContain('useState(0)')
expect(output.code).not.toContain('useState')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants