Skip to content

Commit

Permalink
experiment: lazily load SimulatePreloadedQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Aug 19, 2024
1 parent 8f1ca88 commit da4c6f8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/client-react-streaming/src/index.cc.tsx
Original file line number Diff line number Diff line change
@@ -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<T>({
options,
result,
children,
queryKey,
}: {
options: TransportedQueryRefOptions;
result: Promise<Array<Omit<ProgressEvent, "id">>>;
children: ReactNode;
queryKey?: string;
}): ReactNode {
if (!RealSimulatePreloadedQuery) {
RealSimulatePreloadedQuery = React.lazy(() =>
import("./SimulatePreloadedQuery.cc.js").then((m) => ({
default: m.SimulatePreloadedQuery,
}))
);
}
return (
<RealSimulatePreloadedQuery
options={options}
result={result}
queryKey={queryKey}
>
{children}
</RealSimulatePreloadedQuery>
);
}
10 changes: 9 additions & 1 deletion packages/client-react-streaming/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
];
Expand Down

0 comments on commit da4c6f8

Please sign in to comment.