From 0908c20a7f83b2a2915fe5ff6b44d13378d30103 Mon Sep 17 00:00:00 2001 From: AlexandrHoroshih Date: Sat, 16 Sep 2023 19:20:22 +0700 Subject: [PATCH 1/3] Add a command for easier launch of playground app --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9e402f8..5b34bba 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "build:code": "vite build", "build:types": "tsc", "build:directive": "node ./scripts/inject-use-client.mjs", - "build": "pnpm build:code && pnpm build:types && pnpm build:directive" + "build": "pnpm build:code && pnpm build:types && pnpm build:directive", + "dev:playground-app": "cd apps/playground-app && pnpm dev" }, "devDependencies": { "@babel/core": "^7.21.4", From 582cdee0d4890e5241b54078c69f79175608cc4c Mon Sep 17 00:00:00 2001 From: AlexandrHoroshih Date: Sat, 16 Sep 2023 19:20:52 +0700 Subject: [PATCH 2/3] Fix empty header in the playground app --- apps/playground-app/src/shared/app/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/playground-app/src/shared/app/index.ts b/apps/playground-app/src/shared/app/index.ts index 0fef57b..1f93670 100644 --- a/apps/playground-app/src/shared/app/index.ts +++ b/apps/playground-app/src/shared/app/index.ts @@ -9,7 +9,7 @@ export const pageStarted = createEvent<{ export const $currentPage = createStore<(typeof pageTypes)[number] | null>(null).on( pageStarted, - (_, { pageType }) => pageType + (_, { pageType }) => pageType ?? "unknown_page" ); export function declarePage(config: { From 8d72c9044ea9ad933e8c56ce7e8048dad3740f5e Mon Sep 17 00:00:00 2001 From: AlexandrHoroshih Date: Sat, 16 Sep 2023 19:21:25 +0700 Subject: [PATCH 3/3] Delay state update for one tick to evade setState warning --- src/get-scope.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/get-scope.ts b/src/get-scope.ts index ea20b35..a562222 100644 --- a/src/get-scope.ts +++ b/src/get-scope.ts @@ -116,7 +116,19 @@ function HACK_updateScopeRefs(tscope: Scope, values: Values) { } /** - * Run scheduled watchers + * Delay links run to separate task, + * so React won't agro on us for updating state during render + */ + queueMicrotask(() => { + HACK_runScopeWatchers(scope, linksToRun); + }); +} + +function HACK_runScopeWatchers(scope: ScopeInternal, linksToRun: string[]) { + /** + * Run watchers (`useUnit`, etc) to push new values to them + * + * Manual lauch is required because top-down re-render stops at `memo`-ed components */ if (linksToRun.length) { linksToRun.forEach((nodeId) => {