Skip to content

Commit 9243ca3

Browse files
authored
Enable React Compiler for ComponentEditor and reorganize config (#1511)
## Description Enable React Compiler for `ComponentEditor` directory and optimize component functions by removing unnecessary `useCallback` hooks. This PR: 1. Adds `src/components/shared/ComponentEditor` to the React Compiler enabled directories 2. Reorganizes the order of enabled directories in the config file 3. Removes `useCallback` wrappers from functions in: - `ComponentEditorDialog.tsx` - `PythonComponentEditor.tsx` - `YamlComponentEditor.tsx` 4. Replaces a `useEffect` initialization pattern with a ref-based approach in `PythonComponentEditor.tsx` ## Type of Change - [x] Improvement - [x] Cleanup/Refactor ## Checklist - [ ] I have tested this does not break current pipelines / runs functionality - [ ] I have tested the changes on staging ## Test Instructions 1. Open the Component Editor dialog 2. Test creating and editing components in both YAML and Python modes 3. Verify all functionality works as expected, including saving components and error validation
1 parent dfe4ca7 commit 9243ca3

File tree

5 files changed

+51
-72
lines changed

5 files changed

+51
-72
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react-compiler.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ export const REACT_COMPILER_ENABLED_DIRS = [
2121
"src/components/shared/GitHubAuth",
2222
"src/components/shared/Authentication",
2323
"src/routes",
24+
"src/components/shared/ReactFlow/FlowCanvas/FlowCanvas.tsx",
25+
"src/components/shared/ComponentEditor",
2426

2527
// 6-10 useCallback/useMemo
26-
// "src/components/shared/ComponentEditor", // 6
2728
// "src/components/shared/Settings", // 6
2829
// "src/components/shared/HuggingFaceAuth", // 8
2930

@@ -40,7 +41,6 @@ export const REACT_COMPILER_ENABLED_DIRS = [
4041
// "src/hooks", // 53
4142
// "src/providers", // 75
4243
// "src/components/shared/ReactFlow", // 190
43-
"src/components/shared/ReactFlow/FlowCanvas/FlowCanvas.tsx",
4444
];
4545

4646
// Convert to glob patterns for ESLint

src/components/shared/ComponentEditor/ComponentEditorDialog.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useSuspenseQuery } from "@tanstack/react-query";
2-
import { useCallback, useState } from "react";
2+
import { useState } from "react";
33

44
import { Button } from "@/components/ui/button";
55
import { Icon } from "@/components/ui/icon";
@@ -147,11 +147,11 @@ export const ComponentEditorDialog = withSuspenseWrapper(
147147
},
148148
});
149149

150-
const handleComponentTextChange = useCallback((value: string) => {
150+
const handleComponentTextChange = (value: string) => {
151151
setComponentText(value);
152-
}, []);
152+
};
153153

154-
const handleSave = useCallback(async () => {
154+
const handleSave = async () => {
155155
const hydratedComponent = await hydrateComponentReference({
156156
text: componentText,
157157
});
@@ -174,11 +174,11 @@ export const ComponentEditorDialog = withSuspenseWrapper(
174174
"success",
175175
);
176176
}
177-
}, [componentText, addToComponentLibrary, notify, onClose]);
177+
};
178178

179-
const handleClose = useCallback(() => {
179+
const handleClose = () => {
180180
onClose();
181-
}, [onClose]);
181+
};
182182

183183
const title = text ? "Edit Component" : "New Component";
184184
const hasTemplate = templateName && templateName !== "empty";

src/components/shared/ComponentEditor/components/PythonComponentEditor.tsx

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MonacoEditor from "@monaco-editor/react";
2-
import { useCallback, useEffect, useRef, useState } from "react";
2+
import { useEffect, useRef, useState } from "react";
33

44
import { withSuspenseWrapper } from "@/components/shared/SuspenseWrapper";
55
import { BlockStack, InlineStack } from "@/components/ui/layout";
@@ -67,53 +67,36 @@ export const PythonComponentEditor = withSuspenseWrapper(
6767
const preservedNameRef = useRef(initialComponentName);
6868

6969
useEffect(() => {
70-
preservedNameRef.current = initialComponentName;
71-
}, [initialComponentName]);
70+
handleFunctionTextChange(text);
71+
}, []);
7272

73-
const generateYaml = useCallback(
74-
async (code: string, options: YamlGeneratorOptions) => {
75-
try {
76-
const yaml = await yamlGenerator(code, options);
77-
const yamlWithPreservedName = preserveComponentName(
78-
yaml,
79-
preservedNameRef.current,
80-
);
81-
setComponentText(yamlWithPreservedName);
82-
onComponentTextChange(yamlWithPreservedName);
83-
setValidationErrors([]);
84-
onErrorsChange([]);
85-
} catch (error) {
86-
const errors = [
87-
error instanceof Error ? error.message : String(error),
88-
];
89-
onErrorsChange(errors);
90-
setValidationErrors(errors);
91-
}
92-
},
93-
[yamlGenerator, onComponentTextChange, onErrorsChange],
94-
);
73+
// Sync ref with prop
74+
preservedNameRef.current = initialComponentName;
9575

96-
const handleFunctionTextChange = useCallback(
97-
async (value: string | undefined) => {
98-
const code = value ?? "";
99-
setPythonCode(code);
100-
generateYaml(code, yamlGeneratorOptions);
101-
},
102-
[generateYaml, yamlGeneratorOptions],
103-
);
76+
const handleFunctionTextChange = async (value: string | undefined) => {
77+
const code = value ?? "";
78+
setPythonCode(code);
79+
try {
80+
const yaml = await yamlGenerator(code, yamlGeneratorOptions);
81+
const yamlWithPreservedName = preserveComponentName(
82+
yaml,
83+
preservedNameRef.current,
84+
);
85+
setComponentText(yamlWithPreservedName);
86+
onComponentTextChange(yamlWithPreservedName);
87+
setValidationErrors([]);
88+
onErrorsChange([]);
89+
} catch (error) {
90+
const errors = [error instanceof Error ? error.message : String(error)];
91+
onErrorsChange(errors);
92+
setValidationErrors(errors);
93+
}
94+
};
10495

105-
const handleOptionsChange = useCallback(
106-
(options: YamlGeneratorOptions) => {
107-
setYamlGeneratorOptions(options);
108-
generateYaml(pythonCode, options);
109-
},
110-
[pythonCode, generateYaml],
111-
);
112-
113-
useEffect(() => {
114-
// first time loading
115-
generateYaml(text, options);
116-
}, []);
96+
const handleOptionsChange = (options: YamlGeneratorOptions) => {
97+
setYamlGeneratorOptions(options);
98+
handleFunctionTextChange(pythonCode);
99+
};
117100

118101
return (
119102
<InlineStack className="w-full h-full" gap="4">

src/components/shared/ComponentEditor/components/YamlComponentEditor.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import MonacoEditor from "@monaco-editor/react";
2-
import { useCallback, useState } from "react";
2+
import { useState } from "react";
33

44
import { withSuspenseWrapper } from "@/components/shared/SuspenseWrapper";
55
import { BlockStack, InlineStack } from "@/components/ui/layout";
@@ -23,24 +23,21 @@ export const YamlComponentEditor = withSuspenseWrapper(
2323
const validateComponentSpec = useComponentSpecValidator();
2424
const [validationErrors, setValidationErrors] = useState<string[]>([]);
2525

26-
const handleComponentTextChange = useCallback(
27-
(value: string | undefined) => {
28-
const validationResult = validateComponentSpec(value ?? "");
26+
const handleComponentTextChange = (value: string | undefined) => {
27+
const validationResult = validateComponentSpec(value ?? "");
2928

30-
if (!validationResult.valid) {
31-
const errors = validationResult.errors ?? ["Invalid component spec"];
32-
setValidationErrors(errors);
33-
onErrorsChange(errors);
34-
return;
35-
}
29+
if (!validationResult.valid) {
30+
const errors = validationResult.errors ?? ["Invalid component spec"];
31+
setValidationErrors(errors);
32+
onErrorsChange(errors);
33+
return;
34+
}
3635

37-
setComponentText(value ?? "");
38-
onComponentTextChange(value ?? "");
39-
setValidationErrors([]);
40-
onErrorsChange([]);
41-
},
42-
[onComponentTextChange, validateComponentSpec],
43-
);
36+
setComponentText(value ?? "");
37+
onComponentTextChange(value ?? "");
38+
setValidationErrors([]);
39+
onErrorsChange([]);
40+
};
4441

4542
return (
4643
<InlineStack className="w-full h-full" gap="4">

0 commit comments

Comments
 (0)