FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(react): use SSR transform of React Compiler for server envs by sapphi-red · Pull Request #1438 · vitejs/vite-plugin-react · GitHub

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

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

Conversation

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 commented Aug 27, 2026
edited
Loading

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.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
expect(output.code).not.toContain('useState(0)')
expect(output.code).not.toContain('useState')

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL