Skip to content

Commit b4b5028

Browse files
authored
Integrate React Compiler (#13826)
1 parent 47cd5b0 commit b4b5028

File tree

102 files changed

+663
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+663
-506
lines changed

.distignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ web-stories-scraper
4040
.npmpackagejsonlintrc.json
4141
.npmrc
4242
.nvmrc
43+
.oxlintrc.json
4344
.phpstorm.config.js
4445
.phpstorm.meta.php
4546
.phpunit.result.cache

.eslintrc

+11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"jsx-a11y",
2121
"markdown",
2222
"react",
23+
"react-compiler",
2324
"react-hooks",
2425
"styled-components-a11y"
2526
],
@@ -214,6 +215,15 @@
214215
"react/no-unused-prop-types": "error",
215216
"react/react-in-jsx-scope": "off",
216217
"react/self-closing-comp": "error",
218+
"react-compiler/react-compiler": [
219+
"error",
220+
{
221+
"environment": {
222+
"enableTreatRefLikeIdentifiersAsRefs": true,
223+
"validateRefAccessDuringRender": false
224+
}
225+
}
226+
],
217227
"import/no-extraneous-dependencies": "error",
218228
"import/no-unresolved": "error",
219229
"import/order": [
@@ -422,6 +432,7 @@
422432
"rules": {
423433
"@eslint-community/eslint-comments/require-description": "off",
424434
"react/prop-types": "off",
435+
"react-compiler/react-compiler": "off",
425436
"jest/no-hooks": "off",
426437
"jest/no-untyped-mock-factory": "off",
427438
"jest/max-expects": "off",

.oxlintrc.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"settings": {
3+
"jsdoc": {
4+
"tagNamePreference": {
5+
"returns": "return",
6+
"yields": "yield"
7+
}
8+
}
9+
},
10+
"rules": {
11+
"no-unused-vars": "off"
12+
}
13+
}

.storybook/stories/playground/dashboard/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* External dependencies
1919
*/
20-
import { useRef } from 'react';
20+
import { useRef, useEffect } from 'react';
2121
import { toId } from '@storybook/csf';
2222
import { Dashboard, InterfaceSkeleton } from '@googleforcreators/dashboard';
2323

@@ -102,10 +102,12 @@ const getAuthors = () => Promise.resolve([{ name: 'Author', id: 1 }]);
102102
const useClearHash = () => {
103103
const isHashCleaned = useRef(false);
104104

105-
if (!isHashCleaned.current) {
106-
window.location.hash = '/';
107-
isHashCleaned.current = true;
108-
}
105+
useEffect(() => {
106+
if (!isHashCleaned.current) {
107+
window.location.hash = '/';
108+
isHashCleaned.current = true;
109+
}
110+
}, []);
109111
};
110112

111113
export const _default = {

.storybook/stories/playground/story-editor/header/buttons/preview.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function PreviewButton() {
6868
</script>`
6969
);
7070
}
71-
} catch (e) {
71+
} catch {
7272
// Not interested in the error.
7373
}
7474
};

babel.config.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module.exports = function (api) {
4646
'@babel/preset-typescript',
4747
],
4848
plugins: [
49+
['babel-plugin-react-compiler', { target: '17' }],
4950
'@wordpress/babel-plugin-import-jsx-pragma',
5051
[
5152
'babel-plugin-styled-components',

package-lock.json

+92
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"ajv-formats": "^3.0.1",
101101
"babel-jest": "^29.6.1",
102102
"babel-loader": "^9.2.1",
103+
"babel-plugin-react-compiler": "0.0.0-experimental-63cca73-20250106",
103104
"babel-plugin-styled-components": "^2.1.4",
104105
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
105106
"browserslist": "^4.24.4",
@@ -124,6 +125,7 @@
124125
"eslint-plugin-oxlint": "^0.15.5",
125126
"eslint-plugin-prettier": "^5.2.1",
126127
"eslint-plugin-react": "^7.37.3",
128+
"eslint-plugin-react-compiler": "0.0.0-experimental-63cca73-20250106",
127129
"eslint-plugin-react-hooks": "^5.1.0",
128130
"eslint-plugin-security": "^3.0.1",
129131
"eslint-plugin-styled-components-a11y": "^2.2.0",
@@ -159,6 +161,7 @@
159161
"postcss-syntax": "^0.36.2",
160162
"prettier": "^3.4.2",
161163
"puppeteer": "^23.11.1",
164+
"react-compiler-runtime": "0.0.0-experimental-63cca73-20250106",
162165
"react-refresh": "^0.16.0",
163166
"react-test-renderer": "^17.0.2",
164167
"rollup": "^2.79.2",
@@ -221,9 +224,9 @@
221224
"lint:css:js:fix": "stylelint \"**/*.js\" --fix",
222225
"lint:css:css": "stylelint \"**/*.css\"",
223226
"lint:css:css:fix": "stylelint \"**/*.css\" --fix",
224-
"lint:js": "oxlint && eslint .",
225-
"lint:js:fix": "oxlint --fix && eslint --fix .",
226-
"lint:js:report": "oxlint && eslint --output-file build/lint-js-report.json --format json .",
227+
"lint:js": "oxlint -c=.oxlintrc.json --tsconfig=tsconfig.json --ignore-pattern=@types --react-perf-plugin && eslint .",
228+
"lint:js:fix": "oxlint --fix -c=.oxlintrc.json --tsconfig=tsconfig.json --ignore-pattern=@types --react-perf-plugin && eslint --fix .",
229+
"lint:js:report": "oxlint -c=.oxlintrc.json --tsconfig=tsconfig.json --ignore-pattern=@types --react-perf-plugin && eslint --output-file build/lint-js-report.json --format json .",
227230
"lint:package-json": "npmPkgJsonLint .",
228231
"lint:php": "composer phpcs",
229232
"lint:php:fix": "composer phpcbf",

packages/dashboard/src/app/api/useStoryApi.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ const useStoryApi = () => {
5151
const [state, dispatch] = useReducer(storyReducer, defaultStoriesState);
5252
const { apiCallbacks } = useConfig();
5353

54-
const isMounted = useRef(false);
54+
const isMountedRef = useRef(false);
5555

5656
useEffect(() => {
57-
isMounted.current = true;
57+
isMountedRef.current = true;
5858

5959
return () => {
60-
isMounted.current = false;
60+
isMountedRef.current = false;
6161
};
6262
}, []);
6363

@@ -78,7 +78,7 @@ const useStoryApi = () => {
7878
const { stories, fetchedStoryIds, totalPages, totalStoriesByStatus } =
7979
await apiCallbacks.fetchStories(queryParams);
8080

81-
if (!isMounted.current) {
81+
if (!isMountedRef.current) {
8282
return;
8383
}
8484

packages/dashboard/src/app/views/exploreTemplates/content/templateGridView.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function TemplateGridView({
4848
const { isRTL, apiCallbacks } = useConfig();
4949
const containerRef = useRef();
5050
const gridRef = useRef();
51-
const itemRefs = useRef({});
51+
const itemsRef = useRef({});
5252
const [activeGridItemId, setActiveGridItemId] = useState(null);
5353
const { handleDetailsToggle, createStoryFromTemplate } =
5454
templateActions || {};
@@ -58,7 +58,7 @@ function TemplateGridView({
5858
useGridViewKeys({
5959
containerRef,
6060
gridRef,
61-
itemRefs,
61+
itemRefs: itemsRef,
6262
isRTL,
6363
currentItemId: activeGridItemId,
6464
items: filteredTemplates,
@@ -69,7 +69,7 @@ function TemplateGridView({
6969
// for legibility, it's based on the FOCUS_TEMPLATE_CLASS
7070
useEffect(() => {
7171
if (activeGridItemId) {
72-
itemRefs.current?.[activeGridItemId]
72+
itemsRef.current?.[activeGridItemId]
7373
?.querySelector(`.${FOCUS_TEMPLATE_CLASS}`)
7474
?.focus();
7575
}
@@ -97,7 +97,7 @@ function TemplateGridView({
9797
key={slug}
9898
posterSrc={posterSrc}
9999
ref={(el) => {
100-
itemRefs.current[id] = el;
100+
itemsRef.current[id] = el;
101101
}}
102102
slug={slug}
103103
status={status}

packages/dashboard/src/app/views/myStories/content/storiesView/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function StoriesView({ loading, storyActions, stories, view }) {
113113
const handleOnDeleteStory = useCallback(() => {
114114
trackEvent('delete_story');
115115
storyActions.trashStory(activeStory);
116-
setFocusedStory({ id: activeStory.id, isDeleted: true });
116+
setFocusedStory({ id: activeStory?.id, isDeleted: true });
117117
setActiveDialog('');
118118
}, [storyActions, activeStory]);
119119

@@ -162,6 +162,11 @@ function StoriesView({ loading, storyActions, stories, view }) {
162162
[showSnackbar]
163163
);
164164

165+
const handleCloseConfirmDialog = useCallback(() => {
166+
setFocusedStory({ id: activeStory?.id });
167+
setActiveDialog('');
168+
}, [activeStory]);
169+
165170
const menuItems = STORY_CONTEXT_MENU_ITEMS.map((item) => {
166171
switch (item?.value) {
167172
case STORY_CONTEXT_MENU_ACTIONS.COPY_STORY_LINK:
@@ -257,10 +262,7 @@ function StoriesView({ loading, storyActions, stories, view }) {
257262
isOpen
258263
contentLabel={__('Dialog to confirm deleting a story', 'web-stories')}
259264
title={__('Delete Story', 'web-stories')}
260-
onClose={() => {
261-
setFocusedStory({ id: activeStory.id });
262-
setActiveDialog('');
263-
}}
265+
onClose={handleCloseConfirmDialog}
264266
secondaryText={__('Cancel', 'web-stories')}
265267
secondaryRest={{
266268
['aria-label']: sprintf(

0 commit comments

Comments
 (0)