From 776f2148b441bafb72f19c83b4834dcf33a2a1d0 Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Tue, 31 Oct 2023 13:17:40 -0400 Subject: [PATCH] [feedback] More efficient userspace impl for uMC --- compiler/packages/sprout/src/shared-runtime.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/compiler/packages/sprout/src/shared-runtime.ts b/compiler/packages/sprout/src/shared-runtime.ts index d74d46a661..9bc434d7d0 100644 --- a/compiler/packages/sprout/src/shared-runtime.ts +++ b/compiler/packages/sprout/src/shared-runtime.ts @@ -195,9 +195,11 @@ export const ObjectWithHooks = { const $empty = Symbol.for("react.memo_cache_sentinel"); export function unstable_useMemoCache(size: number) { "use no forget"; - const $ = new Array(size); - for (let ii = 0; ii < size; ii++) { - $[ii] = $empty; - } - return React.useRef($).current; + return React.useState(() => { + const $ = new Array(size); + for (let ii = 0; ii < size; ii++) { + $[ii] = $empty; + } + return $; + })[0]; }