@samitouri / QOS-React-2 / commits / 56d96ba203

[forget-runtime] Remove invariant dep

Reduces a dep needed to be installed by users of the polyfill

Lauren Tan committed Mar 11, 2024 at 16:31 UTC 56d96ba2033496e3458631b02e079c0bf73235e7
1 file changed +11 -10
compiler/packages/react-forget-runtime/src/index.ts
+11 -10
@@ -7,7 +7,6 @@
7
8 "use no forget";
9
10 -import invariant from "invariant";
10 import * as React from "react";
11
12 const {
@@ -160,10 +159,11 @@ export function $dispatcherGuard(kind: GuardKind) {
159 // Pop before checking invariant or errors
160 const lastFrame = guardFrames.pop();
161
163 - invariant(
164 - lastFrame != null,
165 - "React Forget internal error: unexpected null in guard stack"
166 - );
162 + if (lastFrame == null) {
163 + throw new Error(
164 + "React Forget internal error: unexpected null in guard stack"
165 + );
166 + }
167 if (guardFrames.length === 0) {
168 originalDispatcher = null;
169 }
@@ -175,13 +175,14 @@ export function $dispatcherGuard(kind: GuardKind) {
175 setCurrent(originalDispatcher);
176 } else if (kind === GuardKind.PopExpectHook) {
177 const lastFrame = guardFrames.pop();
178 - invariant(
179 - lastFrame != null,
180 - "React Forget internal error: unexpected null in guard stack"
181 - );
178 + if (lastFrame == null) {
179 + throw new Error(
180 + "React Forget internal error: unexpected null in guard stack"
181 + );
182 + }
183 setCurrent(lastFrame);
184 } else {
184 - invariant(false, "Forget internal error: unreachable block" + kind);
185 + throw new Error("Forget internal error: unreachable block" + kind);
186 }
187 }
188