Skip to content

fix(rspack): apply React Compiler to .ts files in babel-ts example (#1) - #517

Merged
chenjiahan merged 4 commits into
rstackjs:mainfrom
heyq02:main
Oct 13, 2026
Merged

chenjiahan merged 4 commits into
rstackjs:mainfrom
heyq02:main

Conversation

@heyq02

@heyq02 heyq02 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Run babel-loader / babel-plugin-react-compiler on .ts files in rspack/react-compiler-babel-ts, not only .tsx (hooks are commonly defined in .ts)
  • Add a small useCounter.ts hook used by App.tsx so the example demonstrates the pattern

Fixes #331

Test plan

  • pnpm --filter "@rspack-example/react-compiler-babel-ts" build succeeds
  • Dev bundle shows useCounter.ts rewritten with react/compiler-runtime memo cache
  • Smoke-test pnpm --filter "@rspack-example/react-compiler-babel-ts" dev — counter button increments

heyq02 and others added 2 commits October 12, 2026 21:56
* fix(rspack): apply React Compiler to .ts files in babel-ts example

Hooks are commonly defined in .ts files, so babel-loader with
babel-plugin-react-compiler should process those as well as .tsx.
Adds a small useCounter.ts hook to demonstrate the pattern.

Fixes rstackjs#331

Co-authored-by: Ari <mail@heyq02.cn>

* style(rspack): make counter button readable in react-compiler-babel-ts

Co-authored-by: Ari <mail@heyq02.cn>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>

chenjiahan commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Thanks for fixing this! Could we switch this example to Rspack's Rust React Compiler instead? Running Babel on every .ts file adds build overhead, and this example already uses a Rspack version that supports the Rust implementation.

With detectSyntax: 'auto', we can consolidate the JS/TS/JSX/TSX rules into a single builtin:swc-loader rule and enable jsc.transform.reactCompiler: true, keeping react.runtime: 'automatic'. That would also let us remove the Babel config and dependencies and rename the example to drop babel.

Copy link
Copy Markdown
Member

Once this is updated, could you also open a PR in the Rspack repository to update the links in the React Compiler examples section to match the new directory names? For example, react-compiler-babel → react-compiler.

@heyq02

heyq02 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

更新完成后,能否也在 Rspack 仓库中提交一个 PR,将React 编译器示例部分中的链接更新为与新的目录名称匹配?例如,react-compiler-babel→ react-compiler。

well

#2)

* refactor(rspack): switch React Compiler examples to builtin:swc-loader

Use Rspack's Rust React Compiler via jsc.transform.reactCompiler instead
of babel-loader. Consolidate JS/TS/JSX/TSX into a single rule with
detectSyntax: 'auto', remove Babel config/deps, and rename examples to
react-compiler and react-compiler-ts.

Addresses review feedback on rstackjs#517.

Co-authored-by: Ari <mail@heyq02.cn>

* chore(rspack): fix package.json conflict and update lockfile

Resolve leftover rebase conflict markers in react-compiler-ts and refresh
pnpm-lock.yaml after renaming the React Compiler examples.

Co-authored-by: Ari <mail@heyq02.cn>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>

@chenjiahan chenjiahan left a comment

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.

Thank you

@chenjiahan
chenjiahan merged commit 84a4c60 into rstackjs:main Oct 13, 2026
1 check passed
@heyq02

heyq02 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thank you

My pleasure.

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.

React Compiler + TypeScript example should run compiler on .ts files as well as .tsx

2 participants