Skip to content

Commit 6b2d335

Browse files
authored
feat/react-forget (#19)
* feat: react forget - setup react forget compiler
1 parent c66b363 commit 6b2d335

File tree

9 files changed

+124
-38
lines changed

9 files changed

+124
-38
lines changed

.babelrc

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"plugins": [
1111
"@loadable/babel-plugin",
1212
["@babel/plugin-proposal-decorators", { "version": "legacy"}],
13+
["babel-plugin-react-compiler", { "runtimeModule": "/config/react-forget" }],
1314
"@babel/plugin-transform-runtime"
1415
]
1516
}

.eslintrc

-24
This file was deleted.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ If you are looking for **renderToPipeableStream** setup switch to the [feat/pipa
1313
- [x] `SPA` mode
1414
- [x] `Polyfills`
1515
- [x] `PWA`
16+
- [x] React forget
1617
- [x] local `https`
1718
- [x] `PipeableStream` support
1819

config/react-forget/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const $empty = Symbol.for('react.memo_cache_sentinel')
2+
const React = require('react')
3+
4+
/**
5+
* DANGER: this hook is NEVER meant to be called directly!
6+
*
7+
* Note that this is a temporary userspace implementation of this function
8+
* from React 19. It is not as efficient and may invalidate more frequently
9+
* than the official API. Please upgrade to React 19 as soon as you can.
10+
**/
11+
export function c(size) {
12+
return React.useState(() => {
13+
const $ = new Array(size)
14+
for (let ii = 0; ii < size; ii++) {
15+
$[ii] = $empty
16+
}
17+
18+
$[$empty] = true
19+
return $
20+
})[0]
21+
}

eslint.config.mjs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import globals from 'globals'
22
import react from 'eslint-plugin-react'
33
import prettier from 'eslint-plugin-prettier'
4+
import reactForget from 'eslint-plugin-react-compiler'
45
import typescriptEslint from '@typescript-eslint/eslint-plugin'
56
import { fixupPluginRules } from '@eslint/compat'
67
import tsParser from '@typescript-eslint/parser'
@@ -14,7 +15,11 @@ export default [
1415
plugins: {
1516
prettier,
1617
'@typescript-eslint': typescriptEslint,
17-
react: fixupPluginRules(react)
18+
'react-compiler': fixupPluginRules(reactForget),
19+
react: fixupPluginRules(react),
20+
},
21+
rules: {
22+
'react-compiler/react-compiler': 'error'
1823
},
1924
languageOptions: {
2025
globals: {

jest.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default {
1616
'^pages/(.*)$': '<rootDir>/src/client/pages/$1',
1717
'^utils/(.*)$': '<rootDir>/src/client/utils/$1',
1818
'^assets/(.*)$': '<rootDir>/src/client/assets/$1',
19+
'/config/react-forget$': '<rootDir>/config/react-forget',
1920
'\\.(icon|image).(svg)$': '<rootDir>/config/spec/svgr.ts',
2021
'\\.(css|scss)$': 'identity-obj-proxy'
2122
}

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@typescript-eslint/parser": "^7.15.0",
8383
"autoprefixer": "^10.4.19",
8484
"babel-loader": "^9.1.3",
85+
"babel-plugin-react-compiler": "^0.0.0-experimental-696af53-20240625",
8586
"copy-webpack-plugin": "^12.0.2",
8687
"cross-env": "^7.0.3",
8788
"css-loader": "7.1.2",
@@ -130,6 +131,7 @@
130131
"workbox-recipes": "^7.1.0",
131132
"workbox-routing": "^7.1.0",
132133
"workbox-strategies": "^7.1.0",
133-
"workbox-webpack-plugin": "^7.1.0"
134+
"workbox-webpack-plugin": "^7.1.0",
135+
"react-compiler-runtime": "file:./config/react-forget"
134136
}
135137
}

src/client/components/@shared/app/app.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type FC, StrictMode } from 'react'
22
import { getENV, type AppProps } from 'src/common'
33
import { HelmetProvider } from 'react-helmet-async'
4+
45
export const App: FC<AppProps> = ({ children, nonce, helmetContext }) => {
56
__webpack_nonce__ = nonce
67
__webpack_public_path__ = getENV('PUBLIC_PATH')

yarn.lock

+90-12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@
7474
json5 "^2.2.3"
7575
semver "^6.3.1"
7676

77+
78+
version "7.2.0"
79+
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.2.0.tgz#eaf3821fa0301d9d4aef88e63d4bcc19b73ba16c"
80+
integrity sha512-BA75MVfRlFQG2EZgFYIwyT1r6xSkwfP2bdkY/kLZusEYWiJs4xCowab/alaEaT0wSvmVuXGqiefeBlP+7V1yKg==
81+
dependencies:
82+
"@babel/types" "^7.2.0"
83+
jsesc "^2.5.1"
84+
lodash "^4.17.10"
85+
source-map "^0.5.0"
86+
trim-right "^1.0.1"
87+
7788
"@babel/generator@^7.24.7", "@babel/generator@^7.7.2":
7889
version "7.24.7"
7990
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.24.7.tgz#1654d01de20ad66b4b4d99c135471bc654c55e6d"
@@ -1120,7 +1131,7 @@
11201131
debug "^4.3.1"
11211132
globals "^11.1.0"
11221133

1123-
"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.21.3", "@babel/types@^7.24.7", "@babel/types@^7.3.3", "@babel/types@^7.4.4":
1134+
"@babel/types@^7.0.0", "@babel/types@^7.19.0", "@babel/types@^7.2.0", "@babel/types@^7.20.7", "@babel/types@^7.21.3", "@babel/types@^7.24.7", "@babel/types@^7.3.3", "@babel/types@^7.4.4":
11241135
version "7.24.7"
11251136
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.24.7.tgz#6027fe12bc1aa724cd32ab113fb7f1988f1f66f2"
11261137
integrity sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q==
@@ -1454,6 +1465,15 @@
14541465
slash "^3.0.0"
14551466
write-file-atomic "^4.0.2"
14561467

1468+
"@jest/types@^24.9.0":
1469+
version "24.9.0"
1470+
resolved "https://registry.yarnpkg.com/@jest/types/-/types-24.9.0.tgz#63cb26cb7500d069e5a389441a7c6ab5e909fc59"
1471+
integrity sha512-XKK7ze1apu5JWQ5eZjHITP66AX+QsLlbaJRBGYr8pNzwcAE2JVkwnf0yqjHTsDRcjR0mujy/NmZMXw5kl+kGBw==
1472+
dependencies:
1473+
"@types/istanbul-lib-coverage" "^2.0.0"
1474+
"@types/istanbul-reports" "^1.1.1"
1475+
"@types/yargs" "^13.0.0"
1476+
14571477
"@jest/types@^29.6.3":
14581478
version "29.6.3"
14591479
resolved "https://registry.yarnpkg.com/@jest/types/-/types-29.6.3.tgz#1131f8cf634e7e84c5e77bab12f052af585fba59"
@@ -2050,6 +2070,14 @@
20502070
dependencies:
20512071
"@types/istanbul-lib-coverage" "*"
20522072

2073+
"@types/istanbul-reports@^1.1.1":
2074+
version "1.1.2"
2075+
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-1.1.2.tgz#e875cc689e47bce549ec81f3df5e6f6f11cfaeb2"
2076+
integrity sha512-P/W9yOX/3oPZSpaYOCQzGqgCQRXn0FFO/V8bWrCQs+wLmvVVxk6CRBXALEvNs9OHIatlnlFokfhuDo2ug01ciw==
2077+
dependencies:
2078+
"@types/istanbul-lib-coverage" "*"
2079+
"@types/istanbul-lib-report" "*"
2080+
20532081
"@types/istanbul-reports@^3.0.0":
20542082
version "3.0.4"
20552083
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz#0f03e3d2f670fbdac586e34b433783070cc16f54"
@@ -2328,6 +2356,13 @@
23282356
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"
23292357
integrity sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==
23302358

2359+
"@types/yargs@^13.0.0":
2360+
version "13.0.12"
2361+
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-13.0.12.tgz#d895a88c703b78af0465a9de88aa92c61430b092"
2362+
integrity sha512-qCxJE1qgz2y0hA4pIxjBR+PelCH0U5CK1XJXFwCNqfmliatKp47UCXXE9Dyk1OXBDLvsCF57TqQEJaeLfDYEOQ==
2363+
dependencies:
2364+
"@types/yargs-parser" "*"
2365+
23312366
"@types/yargs@^17.0.8":
23322367
version "17.0.32"
23332368
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-17.0.32.tgz#030774723a2f7faafebf645f4e5a48371dca6229"
@@ -2673,6 +2708,11 @@ ansi-html@^0.0.9:
26732708
resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.9.tgz#6512d02342ae2cc68131952644a129cb734cd3f0"
26742709
integrity sha512-ozbS3LuenHVxNRh/wdnN16QapUHzauqSomAl1jwwJRRsGwFwtj644lIhxfWu0Fy0acCij2+AEgHvjscq3dlVXg==
26752710

2711+
ansi-regex@^4.0.0:
2712+
version "4.1.1"
2713+
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.1.tgz#164daac87ab2d6f6db3a29875e2d1766582dabed"
2714+
integrity sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==
2715+
26762716
ansi-regex@^5.0.1:
26772717
version "5.0.1"
26782718
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
@@ -2683,7 +2723,7 @@ ansi-regex@^6.0.1:
26832723
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.0.1.tgz#3183e38fae9a65d7cb5e53945cd5897d0260a06a"
26842724
integrity sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==
26852725

2686-
ansi-styles@^3.2.1:
2726+
ansi-styles@^3.2.0, ansi-styles@^3.2.1:
26872727
version "3.2.1"
26882728
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
26892729
integrity sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==
@@ -2941,6 +2981,19 @@ babel-plugin-polyfill-regenerator@^0.6.1:
29412981
dependencies:
29422982
"@babel/helper-define-polyfill-provider" "^0.6.2"
29432983

2984+
babel-plugin-react-compiler@^0.0.0-experimental-696af53-20240625:
2985+
version "0.0.0-experimental-696af53-20240625"
2986+
resolved "https://registry.yarnpkg.com/babel-plugin-react-compiler/-/babel-plugin-react-compiler-0.0.0-experimental-696af53-20240625.tgz#ebf18487ce3fa795a7af78443be0a9f274df8df1"
2987+
integrity sha512-OUDKms8qmcm5bX0D+sJWC1YcKcd7AZ2aJ7eY6gkR+Xr7PDfkXLbqAld4Qs9B0ntjVbUMEtW/PjlQrxDtY4raHg==
2988+
dependencies:
2989+
"@babel/generator" "7.2.0"
2990+
"@babel/types" "^7.19.0"
2991+
chalk "4"
2992+
invariant "^2.2.4"
2993+
pretty-format "^24"
2994+
zod "^3.22.4"
2995+
zod-validation-error "^2.1.0"
2996+
29442997
babel-preset-current-node-syntax@^1.0.0:
29452998
version "1.0.1"
29462999
resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz#b4399239b89b2a011f9ddbe3e4f401fc40cff73b"
@@ -3152,6 +3205,14 @@ caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001599, caniuse-lite@^1.0.30001629:
31523205
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001640.tgz#32c467d4bf1f1a0faa63fc793c2ba81169e7652f"
31533206
integrity sha512-lA4VMpW0PSUrFnkmVuEKBUovSWKhj7puyCg8StBChgu298N1AtuF1sKWEvfDuimSEDbhlb/KqPKC3fs1HbuQUA==
31543207

3208+
chalk@4, chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.2:
3209+
version "4.1.2"
3210+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
3211+
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
3212+
dependencies:
3213+
ansi-styles "^4.1.0"
3214+
supports-color "^7.1.0"
3215+
31553216
chalk@^2.4.1, chalk@^2.4.2:
31563217
version "2.4.2"
31573218
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
@@ -3169,14 +3230,6 @@ chalk@^3.0.0:
31693230
ansi-styles "^4.1.0"
31703231
supports-color "^7.1.0"
31713232

3172-
chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.2:
3173-
version "4.1.2"
3174-
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
3175-
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
3176-
dependencies:
3177-
ansi-styles "^4.1.0"
3178-
supports-color "^7.1.0"
3179-
31803233
chalk@~5.3.0:
31813234
version "5.3.0"
31823235
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385"
@@ -6434,7 +6487,7 @@ lodash.uniq@^4.5.0:
64346487
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
64356488
integrity sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==
64366489

6437-
lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21:
6490+
lodash@^4.17.10, lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21:
64386491
version "4.17.21"
64396492
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
64406493
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
@@ -7555,6 +7608,16 @@ pretty-error@^4.0.0:
75557608
lodash "^4.17.20"
75567609
renderkid "^3.0.0"
75577610

7611+
pretty-format@^24:
7612+
version "24.9.0"
7613+
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"
7614+
integrity sha512-00ZMZUiHaJrNfk33guavqgvfJS30sLYf0f8+Srklv0AMPodGGHcoHgksZ3OThYnIvOd+8yMCn0YiEOogjlgsnA==
7615+
dependencies:
7616+
"@jest/types" "^24.9.0"
7617+
ansi-regex "^4.0.0"
7618+
ansi-styles "^3.2.0"
7619+
react-is "^16.8.4"
7620+
75587621
pretty-format@^27.0.2:
75597622
version "27.5.1"
75607623
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e"
@@ -7689,7 +7752,7 @@ react-helmet-async@^2.0.5:
76897752
react-fast-compare "^3.2.2"
76907753
shallowequal "^1.1.0"
76917754

7692-
react-is@^16.12.0, react-is@^16.13.1, react-is@^16.7.0:
7755+
react-is@^16.12.0, react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.4:
76937756
version "16.13.1"
76947757
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
76957758
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
@@ -8356,6 +8419,11 @@ source-map-support@^0.5.16, source-map-support@~0.5.20:
83568419
buffer-from "^1.0.0"
83578420
source-map "^0.6.0"
83588421

8422+
source-map@^0.5.0:
8423+
version "0.5.7"
8424+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
8425+
integrity sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==
8426+
83598427
source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1:
83608428
version "0.6.1"
83618429
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
@@ -8963,6 +9031,11 @@ tree-dump@^1.0.1:
89639031
resolved "https://registry.yarnpkg.com/tree-dump/-/tree-dump-1.0.2.tgz#c460d5921caeb197bde71d0e9a7b479848c5b8ac"
89649032
integrity sha512-dpev9ABuLWdEubk+cIaI9cHwRNNDjkBBLXTwI4UCUFdQ5xXKqNXoK4FEciw/vxf+NQ7Cb7sGUyeUtORvHIdRXQ==
89659033

9034+
trim-right@^1.0.1:
9035+
version "1.0.1"
9036+
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
9037+
integrity sha512-WZGXGstmCWgeevgTL54hrCuw1dyMQIzWy7ZfqRJfSmJZBwklI15egmQytFP6bPidmw3M8d5yEowl1niq4vmqZw==
9038+
89669039
triple-beam@^1.3.0:
89679040
version "1.4.1"
89689041
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.4.1.tgz#6fde70271dc6e5d73ca0c3b24e2d92afb7441984"
@@ -9882,6 +9955,11 @@ yup@^1.4.0:
98829955
toposort "^2.0.2"
98839956
type-fest "^2.19.0"
98849957

9958+
zod-validation-error@^2.1.0:
9959+
version "2.1.0"
9960+
resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-2.1.0.tgz#208eac75237dfed47c0018d2fe8fd03501bfc9ac"
9961+
integrity sha512-VJh93e2wb4c3tWtGgTa0OF/dTt/zoPCPzXq4V11ZjxmEAFaPi/Zss1xIZdEB5RD8GD00U0/iVXgqkF77RV7pdQ==
9962+
98859963
zod-validation-error@^3.0.3:
98869964
version "3.3.0"
98879965
resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-3.3.0.tgz#2cfe81b62d044e0453d1aa3ae7c32a2f36dde9af"

0 commit comments

Comments
 (0)