From da4c6f8705bd78a789073521cda81c1a8e5afe01 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Mon, 19 Aug 2024 09:54:26 +0200 Subject: [PATCH] experiment: lazily load SimulatePreloadedQuery --- ...dex.cc.ts => SimulatePreloadedQuery.cc.ts} | 0 .../client-react-streaming/src/index.cc.tsx | 36 +++++++++++++++++++ .../client-react-streaming/tsup.config.ts | 10 +++++- 3 files changed, 45 insertions(+), 1 deletion(-) rename packages/client-react-streaming/src/{index.cc.ts => SimulatePreloadedQuery.cc.ts} (100%) create mode 100644 packages/client-react-streaming/src/index.cc.tsx diff --git a/packages/client-react-streaming/src/index.cc.ts b/packages/client-react-streaming/src/SimulatePreloadedQuery.cc.ts similarity index 100% rename from packages/client-react-streaming/src/index.cc.ts rename to packages/client-react-streaming/src/SimulatePreloadedQuery.cc.ts diff --git a/packages/client-react-streaming/src/index.cc.tsx b/packages/client-react-streaming/src/index.cc.tsx new file mode 100644 index 00000000..3ec73b28 --- /dev/null +++ b/packages/client-react-streaming/src/index.cc.tsx @@ -0,0 +1,36 @@ +"use client"; + +import type { ProgressEvent } from "./DataTransportAbstraction/DataTransportAbstraction.js"; +import type { ReactNode } from "react"; +import type { TransportedQueryRefOptions } from "./transportedQueryRef.js"; +import * as React from "react"; + +let RealSimulatePreloadedQuery: typeof SimulatePreloadedQuery; +export function SimulatePreloadedQuery({ + options, + result, + children, + queryKey, +}: { + options: TransportedQueryRefOptions; + result: Promise>>; + children: ReactNode; + queryKey?: string; +}): ReactNode { + if (!RealSimulatePreloadedQuery) { + RealSimulatePreloadedQuery = React.lazy(() => + import("./SimulatePreloadedQuery.cc.js").then((m) => ({ + default: m.SimulatePreloadedQuery, + })) + ); + } + return ( + + {children} + + ); +} diff --git a/packages/client-react-streaming/tsup.config.ts b/packages/client-react-streaming/tsup.config.ts index 1c257480..d846163c 100644 --- a/packages/client-react-streaming/tsup.config.ts +++ b/packages/client-react-streaming/tsup.config.ts @@ -71,7 +71,15 @@ export default defineConfig((options) => { ), entry("ssr", "src/stream-utils/index.ts", "stream-utils.node"), { - ...entry("browser", "src/index.cc.ts", "index.cc"), + ...entry("browser", "src/index.cc.tsx", "index.cc"), + treeshake: false, // would remove the "use client" directive + }, + { + ...entry( + "browser", + "src/SimulatePreloadedQuery.cc.ts", + "SimulatePreloadedQuery.cc" + ), treeshake: false, // would remove the "use client" directive }, ];