Remove memoizeJsxElements flag
Joe Savona committed
Apr 1, 2024 at 15:34 UTC
ef285e0702e7b6a928d6f44480e38a1ddfff976a
5 files changed
+6
-89
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
-7
@@ -161,13 +161,6 @@ const EnvironmentConfigSchema = z.object({
161
// 🌲
162
enableForest: z.boolean().default(false),
163
164
- /*
165
- * Enable memoization of JSX elements in addition to other types of values. When disabled,
166
- * other types (objects, arrays, call expressions, etc) are memoized, but not known JSX
167
- * values.
168
- */
169
- memoizeJsxElements: z.boolean().default(true),
170
-
164
/**
165
* Enable use of type annotations in the source to drive type inference. By default
166
* Forget attemps to infer types using only information that is guaranteed correct
compiler/packages/babel-plugin-react-forget/src/ReactiveScopes/PruneNonEscapingScopes.ts
+1
-2
@@ -776,8 +776,7 @@ class CollectDependenciesVisitor extends ReactiveFunctionVisitor<State> {
776
super();
777
this.env = env;
778
this.options = {
779
- memoizeJsxElements:
780
- this.env.config.memoizeJsxElements && !this.env.config.enableForest,
779
+ memoizeJsxElements: !this.env.config.enableForest,
780
forceMemoizePrimitives: this.env.config.enableForest,
781
};
782
}
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/disable-jsx-memoization.expect.md
deleted
-57
@@ -1,57 +0,0 @@
1
-
2
-## Input
3
-
4
-```javascript
5
-// @memoizeJsxElements:false
6
-function Component(props) {
7
- const [name, setName] = useState(null);
8
- const onChange = function (e) {
9
- setName(e.target.value);
10
- };
11
- return (
12
- <form>
13
- <input onChange={onChange} value={name} />
14
- </form>
15
- );
16
-}
17
-
18
-export const FIXTURE_ENTRYPOINT = {
19
- fn: Component,
20
- params: ["TodoAdd"],
21
- isComponent: "TodoAdd",
22
-};
23
-
24
-```
25
-
26
-## Code
27
-
28
-```javascript
29
-import { unstable_useMemoCache as useMemoCache } from "react"; // @memoizeJsxElements:false
30
-function Component(props) {
31
- const $ = useMemoCache(1);
32
- const [name, setName] = useState(null);
33
- let t0;
34
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
35
- t0 = function (e) {
36
- setName(e.target.value);
37
- };
38
- $[0] = t0;
39
- } else {
40
- t0 = $[0];
41
- }
42
- const onChange = t0;
43
- return (
44
- <form>
45
- <input onChange={onChange} value={name} />
46
- </form>
47
- );
48
-}
49
-
50
-export const FIXTURE_ENTRYPOINT = {
51
- fn: Component,
52
- params: ["TodoAdd"],
53
- isComponent: "TodoAdd",
54
-};
55
-
56
-```
57
-
\ No newline at end of file
compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/disable-jsx-memoization.js
deleted
-18
@@ -1,18 +0,0 @@
1
-// @memoizeJsxElements:false
2
-function Component(props) {
3
- const [name, setName] = useState(null);
4
- const onChange = function (e) {
5
- setName(e.target.value);
6
- };
7
- return (
8
- <form>
9
- <input onChange={onChange} value={name} />
10
- </form>
11
- );
12
-}
13
-
14
-export const FIXTURE_ENTRYPOINT = {
15
- fn: Component,
16
- params: ["TodoAdd"],
17
- isComponent: "TodoAdd",
18
-};
compiler/packages/babel-plugin-react-forget/src/__tests__/parseConfigPragma-test.ts
+5
-5
@@ -13,18 +13,18 @@ describe("parseConfigPragma()", () => {
13
14
// Validate defaults first to make sure that the parser is getting the value from the pragma,
15
// and not just missing it and getting the default value
16
- expect(defaultConfig.enableForest).toBe(false);
16
+ expect(defaultConfig.enableUseTypeAnnotations).toBe(false);
17
expect(defaultConfig.validateRefAccessDuringRender).toBe(false);
18
- expect(defaultConfig.memoizeJsxElements).toBe(true);
18
+ expect(defaultConfig.validateNoSetStateInRender).toBe(true);
19
20
const config = parseConfigPragma(
21
- "@enableForest @validateRefAccessDuringRender:true @memoizeJsxElements:false"
21
+ "@enableUseTypeAnnotations @validateRefAccessDuringRender:true @validateNoSetStateInRender:false"
22
);
23
expect(config).toEqual({
24
...defaultConfig,
25
- enableForest: true,
25
+ enableUseTypeAnnotations: true,
26
validateRefAccessDuringRender: true,
27
- memoizeJsxElements: false,
27
+ validateNoSetStateInRender: false,
28
});
29
});
30
});