Commit Graph

10 Commits

Author SHA1 Message Date
Lauren Tan
f01f74d9e1 Also build react-forget-runtime with rollup
This adds rollup to the runtime and adds a new plugin to add the license banner 
+ inject the `"use no memo"` directive. We need to inject it there as rollup 
currently strips out unknown directives during bundling.
2024-04-02 12:13:40 -04:00
Lauren Tan
ba661c80f3 Remove comments in builds 2024-04-02 10:32:24 -04:00
Lauren Tan
4e6aa42773 Upgrade to typescript 5.4.3
This PR makes all packages share the same typescript version and updates us to 
latest versions of typescript, ts-node, typescript-eslint/eslint-plugin and 
typescript-eslint/parser. 

I also noticed that the tsconfig we were extending (node18-strictest) was 
deprecated, so I switched us over to one that's more up to date. 

Also had to make a couple of small changes to the playground so that continues 
to build correctly.
2024-04-02 10:32:23 -04:00
Lauren Tan
56d96ba203 [forget-runtime] Remove invariant dep
Reduces a dep needed to be installed by users of the polyfill
2024-03-11 16:31:46 -04:00
Lauren Tan
d3bca420c0 Opt out react-forget-runtime from being Forgotten
This caused a build error when Forget was used in an Expo app as the 
react-forget-runtime package was itself being compiled with Forget. This broke 
Metro as metro serializes modules to iifes, but the import syntax that was 
injected by the useMemoCachePolyfill flag was left behind 

In practice I don't think the runtime package needs to ever be compiled by 
Forget, so this PR opts out the whole file. This would also prevent builds from 
breaking if someone decided to use the "all" compilation mode. 

Test plan: Ran the expo app and verified that it now builds with no errors
2024-02-15 17:44:44 -05:00
Mofei Zhang
41b164ed24 [validation] Runtime validation for hook calls
--- 

I modeled guards as try-finally blocks to be extremely explicit. An alternative 
implementation could flatten all nested hooks and only set / restore hook guards 
when entering / exiting a React function (i.e. hook or component) -- this 
alternative approach would be the easiest to represent as a separate pass 

```js 

// source 

function Foo() { 

const result = useHook(useContext(Context)); 

... 

} 

// current output 

function Foo() { 

try { 

pushHookGuard(); 

const result = (() => { 

try { 

pushEnableHook(); 

return useHook((() => { 

try { 

pushEnableHook(); 

return useContext(Context); 

} finally { 

popEnableHook(); 

} 

})()); 

} finally { 

popEnableHook(); 

}; 

})(); 

// ... 

} finally { 

popHookGuard(); 

} 

} 

// alternative output 

function Foo() { 

try { 

// check current is not lazyDispatcher; 

// save originalDispatcher, set lazyDispatcher 

pushHookGuard(); 

allowHook(); // always set originalDispatcher 

const t0 = useContext(Context); 

disallowHook(); // always set LazyDispatcher 

allowHook(); // always set originalDispatcher 

const result = useHook(t0); 

disallowHook(); // always set LazyDispatcher 

// ... 

} finally { 

popHookGuard(); // restore originalDispatcher 

} 

} 

``` 

Checked that IG Web works as expected 

Unless I add a sneaky useState: 

<img width="705" alt="Screenshot 2023-12-05 at 6 44 59 PM" 
src="https://github.com/facebook/react-forget/assets/34200447/3790bd76-7d71-44b5-a62e-f53256fb5736">
2023-12-05 15:02:34 -05:00
Lauren Tan
c289d098d7 [babel] Rename useMemoCacheSource to enableUseMemoCachePolyfill 2023-11-01 13:28:18 -04:00
Lauren Tan
139336b87c [feedback] Specify react dep for react-forget-runtime 2023-11-01 13:12:09 -04:00
Mofei Zhang
e36c8cb395 [patch] tsconfig: unbreak vercel build on main 2023-08-30 10:36:46 -07:00
lauren
a0dc166991 [rfc] Remove top level forget directory
Sorry about the thrash in advance! This removes the top level `forget` directory 
which adds unnecessary nesting to our repo 

Hopefully everything still works
2023-08-22 15:04:54 -04:00