Allow global mutation within useEffect (#2646)

Summary: Currently Forget bails on mutations to globals within any callback function. However, callbacks passed to useEffect should not bail and are not subject to the rules of react in the same way.

We allow this by instead of immediately raising errors when we see illegal writes, storing the error as part of the function. When the function is called, or passed to a position that could call it during rendering, we bail as before; but if it's passed to `useEffect`, we don't raise the errors.
This commit is contained in:
Michael Vitousek
2024-03-05 11:54:29 -08:00
parent f5d99baf8e
commit 22ea72d4e9
9 changed files with 349 additions and 51 deletions
@@ -165,6 +165,12 @@ export class CompilerError extends Error {
throw errors;
}
static throw(options: CompilerErrorDetailOptions): never {
const errors = new CompilerError();
errors.pushErrorDetail(new CompilerErrorDetail(options));
throw errors;
}
constructor(...args: any[]) {
super(...args);
this.name = "ReactForgetCompilerError";