diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.expect.md new file mode 100644 index 0000000000..7dfcddf3f1 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.expect.md @@ -0,0 +1,38 @@ + +## Input + +```javascript +// @flow @gating +component Foo(ref: React.RefSetter) { + return ; +} +``` + +## Code + +```javascript +import { isForgetEnabled_Fixtures } from "ReactForgetFeatureFlag"; +import { unstable_useMemoCache as useMemoCache } from "react"; +const Foo = React.forwardRef(Foo_withRef); +const Foo_withRef = isForgetEnabled_Fixtures() + ? function Foo_withRef(_$$empty_props_placeholder$$, ref) { + const $ = useMemoCache(2); + let t0; + if ($[0] !== ref) { + t0 = ; + $[0] = ref; + $[1] = t0; + } else { + t0 = $[1]; + } + return t0; + } + : function Foo_withRef( + _$$empty_props_placeholder$$: $ReadOnly<{ ... }>, + ref: React.RefSetter + ) { + return ; + }; + +``` + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.js new file mode 100644 index 0000000000..4506f0ab39 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/component-syntax-ref-gating.flow.js @@ -0,0 +1,4 @@ +// @flow @gating +component Foo(ref: React.RefSetter) { + return ; +} \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md new file mode 100644 index 0000000000..e8769a30f6 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.expect.md @@ -0,0 +1,20 @@ + +## Input + +```javascript +// @gating +const Foo = React.forwardRef(Foo_withRef); +function Foo_withRef(props, ref) { + return ; +} + +``` + + +## Error + +``` +[ReactForget] Invariant: Encountered Foo_withRef used before declaration which breaks Forget's gating codegen due to hoisting. Rewrite the reference to not use hoisting to fix this issue (3:3) +``` + + \ No newline at end of file diff --git a/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.js b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.js new file mode 100644 index 0000000000..f0a2879c09 --- /dev/null +++ b/compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.gating-hoisting.js @@ -0,0 +1,5 @@ +// @gating +const Foo = React.forwardRef(Foo_withRef); +function Foo_withRef(props, ref) { + return ; +} diff --git a/compiler/packages/sprout/src/SproutTodoFilter.ts b/compiler/packages/sprout/src/SproutTodoFilter.ts index 2ed99b64a6..c7780ada4c 100644 --- a/compiler/packages/sprout/src/SproutTodoFilter.ts +++ b/compiler/packages/sprout/src/SproutTodoFilter.ts @@ -514,6 +514,7 @@ const skipFilter = new Set([ // bug "bug-jsx-memberexpr-tag-in-lambda", "bug-invalid-code-when-bailout", + "component-syntax-ref-gating.flow", ]); export default skipFilter;