-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
experiment: lazily load SimulatePreloadedQuery
- Loading branch information
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters