-
Notifications
You must be signed in to change notification settings - Fork 109
feat: support react compiler for ReactLynx #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
upupming
wants to merge
33
commits into
lynx-family:main
Choose a base branch
from
upupming:feat/react-compiler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,757
−185
Open
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f242ba4
feat: support react compiler
upupming 3dd46d9
feat: using isReactCompilerRequiredSync
upupming da7ffeb
chore: clean files
upupming acc732c
feat: using @babel/core from user project
upupming cfcc727
feat: add basic test for react compiler
upupming 5b579e8
feat: migrate all test cases from react to examples/react-compiler
upupming c019700
Merge remote-tracking branch 'gh/main' into feat/react-compiler
upupming 04c3b39
fix: resolve rabbitai comments
upupming fbb1e51
chore: remove eslint config
upupming 60f4895
feat: update api.md
upupming eb7a111
fix: no map in build
upupming c6cf035
fix: alias in windows
upupming ce25b02
fix: preact alias to mjs
upupming 675e03c
Merge remote-tracking branch 'gh/main' into feat/react-compiler
upupming 2cd7cda
feat: add `react-compiler-runtime` alias to make 3rd lib works
upupming ec8da4a
feat: use isReactCompilerRequired from @swc/react-compiler
upupming fc294a7
chore: update package.json
upupming 3341d02
Merge remote-tracking branch 'gh/main' into feat/react-compiler
upupming 828aa71
fix: test cases
upupming 3b6992a
Merge remote-tracking branch 'gh/main' into feat/react-compiler
upupming 6dd913b
fix: eslint error
upupming 6f8ada6
Merge remote-tracking branch 'gh/main' into feat/react-compiler
upupming 26b8200
chore: update changeset
upupming ade0dcc
fix: vitest.config.js
upupming 1b224c8
feat: support compiler ts for vitest.config
upupming 0dff201
Update packages/react/testing-library/src/vitest.config.js
upupming 6061e0f
Merge remote-tracking branch 'gh/main' into feat/react-compiler
upupming b97cf8b
feat: process.cwd() -> rootContext
upupming 566c6e6
feat: handle input sourcemap in react compiler loader
upupming 068a3bf
Merge remote-tracking branch 'gh/main' into feat/react-compiler
upupming eb47053
feat: use @rsbuild/plugin-babel
upupming a52d7b6
feat: add dedupe test
upupming 7b24c48
Update .changeset/sour-weeks-wait.md
upupming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| --- | ||
| "@lynx-js/react-rsbuild-plugin": patch | ||
| --- | ||
|
|
||
| Add `react-compiler-runtime` to `resolve.dedupe`. | ||
|
|
||
| With this change you can setup [React Compiler](https://react.dev/learn/react-compiler) for ReactLynx by `pluginBabel`: | ||
|
|
||
| ```js | ||
| import { pluginBabel } from '@rsbuild/plugin-babel'; | ||
upupming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| pluginBabel({ | ||
| include: /\.(?:jsx|tsx)$/, | ||
| babelLoaderOptions(opts) { | ||
| opts.plugins?.unshift([ | ||
| 'babel-plugin-react-compiler', | ||
| // See https://react.dev/reference/react-compiler/configuration for config | ||
| { | ||
| // ReactLynx only supports target to version 17 | ||
| target: '17', | ||
| }, | ||
| ]); | ||
| }, | ||
| }), | ||
| ], | ||
| }); | ||
| ``` | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| "@lynx-js/react": patch | ||
| --- | ||
|
|
||
| Support testing React Compiler in testing library. Enable React Compiler by setting the `experimental_enableReactCompiler` option of `createVitestConfig` to `true`. | ||
|
|
||
| ```js | ||
| import { defineConfig, mergeConfig } from 'vitest/config'; | ||
| import { createVitestConfig } from '@lynx-js/react/testing-library/vitest-config'; | ||
|
|
||
| const defaultConfig = await createVitestConfig({ | ||
| runtimePkgName: '@lynx-js/react', | ||
| experimental_enableReactCompiler: true, | ||
| }); | ||
|
|
||
| export default mergeConfig(defaultConfig, config); | ||
| ``` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { pluginBabel } from '@rsbuild/plugin-babel'; | ||
|
|
||
| import { pluginQRCode } from '@lynx-js/qrcode-rsbuild-plugin'; | ||
| import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'; | ||
| import { defineConfig } from '@lynx-js/rspeedy'; | ||
|
|
||
| const enableBundleAnalysis = !!process.env['RSPEEDY_BUNDLE_ANALYSIS']; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| pluginReactLynx(), | ||
| pluginBabel({ | ||
| include: /\.(?:jsx|tsx)$/, | ||
| babelLoaderOptions(opts) { | ||
| opts.plugins?.unshift([ | ||
| 'babel-plugin-react-compiler', | ||
| // See https://react.dev/reference/react-compiler/configuration for config | ||
| { | ||
| // ReactLynx only supports target to version 17 | ||
| target: '17', | ||
| }, | ||
| ]); | ||
| }, | ||
upupming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }), | ||
| pluginQRCode({ | ||
| schema(url) { | ||
| // We use `?fullscreen=true` to open the page in LynxExplorer in full screen mode | ||
| return `${url}?fullscreen=true`; | ||
| }, | ||
| }), | ||
| ], | ||
| performance: { | ||
| profile: enableBundleAnalysis, | ||
| }, | ||
| }); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "@lynx-js/example-react-compiler", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "rspeedy build", | ||
| "dev": "rspeedy dev" | ||
| }, | ||
| "dependencies": { | ||
| "@lynx-js/react": "workspace:*", | ||
| "react-compiler-runtime": "0.0.0-experimental-0566679-20250709" | ||
| }, | ||
| "devDependencies": { | ||
| "@lynx-js/qrcode-rsbuild-plugin": "workspace:*", | ||
| "@lynx-js/react-rsbuild-plugin": "workspace:*", | ||
| "@lynx-js/rspeedy": "workspace:*", | ||
| "@lynx-js/types": "3.4.11", | ||
| "@rsbuild/plugin-babel": "^1.0.6", | ||
| "@types/react": "^18.3.25", | ||
| "babel-plugin-react-compiler": "0.0.0-experimental-0566679-20250709" | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| :root { | ||
| background-color: #000; | ||
| --color-text: #fff; | ||
| } | ||
|
|
||
| .Background { | ||
| position: fixed; | ||
| background: radial-gradient( | ||
| 71.43% 62.3% at 46.43% 36.43%, | ||
| rgba(18, 229, 229, 0) 15%, | ||
| rgba(239, 155, 255, 0.3) 56.35%, | ||
| #ff6448 100% | ||
| ); | ||
| box-shadow: 0px 12.93px 28.74px 0px #ffd28db2 inset; | ||
| border-radius: 50%; | ||
| width: 200vw; | ||
| height: 200vw; | ||
| top: -60vw; | ||
| left: -14.27vw; | ||
| transform: rotate(15.25deg); | ||
| } | ||
|
|
||
| .App { | ||
| position: relative; | ||
| min-height: 100vh; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| text { | ||
| color: var(--color-text); | ||
| } | ||
|
|
||
| .Banner { | ||
| flex: 5; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| z-index: 100; | ||
| } | ||
|
|
||
| .Logo { | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .Logo--react { | ||
| width: 100px; | ||
| height: 100px; | ||
| animation: Logo--spin infinite 20s linear; | ||
| } | ||
|
|
||
| .Logo--lynx { | ||
| width: 100px; | ||
| height: 100px; | ||
| animation: Logo--shake infinite 0.5s ease; | ||
| } | ||
|
|
||
| @keyframes Logo--spin { | ||
| from { | ||
| transform: rotate(0deg); | ||
| } | ||
| to { | ||
| transform: rotate(360deg); | ||
| } | ||
| } | ||
|
|
||
| @keyframes Logo--shake { | ||
| 0% { | ||
| transform: scale(1); | ||
| } | ||
| 50% { | ||
| transform: scale(0.9); | ||
| } | ||
| 100% { | ||
| transform: scale(1); | ||
| } | ||
| } | ||
|
|
||
| .Content { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .Arrow { | ||
| width: 24px; | ||
| height: 24px; | ||
| } | ||
|
|
||
| .Title { | ||
| font-size: 36px; | ||
| font-weight: 700; | ||
| } | ||
|
|
||
| .Subtitle { | ||
| font-style: italic; | ||
| font-size: 22px; | ||
| font-weight: 600; | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .Description { | ||
| font-size: 20px; | ||
| color: rgba(255, 255, 255, 0.85); | ||
| margin: 15rpx; | ||
upupming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| .Hint { | ||
| font-size: 12px; | ||
| margin: 5px; | ||
| color: rgba(255, 255, 255, 0.65); | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { useCallback, useEffect, useState } from '@lynx-js/react'; | ||
|
|
||
| import './App.css'; | ||
| import arrow from './assets/arrow.png'; | ||
| import lynxLogo from './assets/lynx-logo.png'; | ||
| import reactLynxLogo from './assets/react-logo.png'; | ||
|
|
||
| function Hello({ name }: { | ||
| name: string; | ||
| }) { | ||
| const items = [1, 2, 3].map(item => { | ||
| return <text key={item}>Item {item}</text>; | ||
| }); | ||
| return ( | ||
| <text> | ||
| Hello {name} | ||
| {items} | ||
| </text> | ||
| ); | ||
| } | ||
|
|
||
| export function App() { | ||
| const [alterLogo, setAlterLogo] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| console.info('Hello, ReactLynx'); | ||
| }, []); | ||
|
|
||
| const onTap = useCallback(() => { | ||
| 'background-only'; | ||
| setAlterLogo(!alterLogo); | ||
| }, [alterLogo]); | ||
upupming marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <view> | ||
| <view className='Background' /> | ||
| <view className='App'> | ||
| <view className='Banner'> | ||
| <view className='Logo' bindtap={onTap}> | ||
| {alterLogo | ||
| ? <image src={reactLynxLogo} className='Logo--react' /> | ||
| : <image src={lynxLogo} className='Logo--lynx' />} | ||
| </view> | ||
| <text className='Title'>React</text> | ||
| <text className='Subtitle'>on Lynx</text> | ||
| <Hello name='Lynx' /> | ||
| </view> | ||
| <view className='Content'> | ||
| <image src={arrow} className='Arrow' /> | ||
| <text className='Description'>Tap the logo and have fun!</text> | ||
| <text className='Hint'> | ||
| Edit<text | ||
| style={{ | ||
| fontStyle: 'italic', | ||
| color: 'rgba(255, 255, 255, 0.85)', | ||
| }} | ||
| > | ||
| {' src/App.tsx '} | ||
| </text> | ||
| to see updates! | ||
| </text> | ||
| </view> | ||
| <view style={{ flex: 1 }}></view> | ||
| </view> | ||
| </view> | ||
| ); | ||
| } | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { root } from '@lynx-js/react'; | ||
|
|
||
| import { App } from './App.js'; | ||
|
|
||
| root.render( | ||
| <App />, | ||
| ); | ||
|
|
||
| if (import.meta.webpackHot) { | ||
| import.meta.webpackHot.accept(); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /// <reference types="@lynx-js/rspeedy/client" /> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "jsx": "react-jsx", | ||
| "jsxImportSource": "@lynx-js/react", | ||
| "noEmit": true, | ||
|
|
||
| "allowJs": true, | ||
| "checkJs": true, | ||
| "isolatedDeclarations": false, | ||
| }, | ||
| "include": ["src", "lynx.config.ts", "test"], | ||
| "references": [ | ||
| { "path": "../../packages/react/tsconfig.json" }, | ||
| { "path": "../../packages/rspeedy/core/tsconfig.build.json" }, | ||
| { "path": "../../packages/rspeedy/plugin-qrcode/tsconfig.build.json" }, | ||
| { "path": "../../packages/rspeedy/plugin-react/tsconfig.build.json" }, | ||
| ], | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.