0.1.0 #1
@@ -99,9 +99,18 @@ export const useSuspenseFC: {
|
|||||||
const scope = Runtime.runSync(runtimeRef.current)(Hook.useScope([], self.options))
|
const scope = Runtime.runSync(runtimeRef.current)(Hook.useScope([], self.options))
|
||||||
|
|
||||||
const FC = React.useMemo(() => {
|
const FC = React.useMemo(() => {
|
||||||
const f = (props: P) => Runtime.runSync(runtimeRef.current)(
|
const inner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise)
|
||||||
Effect.provideService(self(props), Scope.Scope, scope)
|
|
||||||
)
|
const f = React.memo((props: P) => {
|
||||||
|
const promise = Runtime.runPromise(runtimeRef.current)(
|
||||||
|
Effect.provideService(self(props), Scope.Scope, scope)
|
||||||
|
)
|
||||||
|
return React.createElement(
|
||||||
|
React.Suspense,
|
||||||
|
{ fallback: "Loading..." },
|
||||||
|
React.createElement(inner, { promise }),
|
||||||
|
)
|
||||||
|
})
|
||||||
f.displayName = self.displayName ?? "Anonymous"
|
f.displayName = self.displayName ?? "Anonymous"
|
||||||
return f
|
return f
|
||||||
}, [scope])
|
}, [scope])
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
import { Route as rootRouteImport } from './routes/__root'
|
import { Route as rootRouteImport } from './routes/__root'
|
||||||
import { Route as BlankRouteImport } from './routes/blank'
|
import { Route as BlankRouteImport } from './routes/blank'
|
||||||
|
import { Route as AsyncRenderingRouteImport } from './routes/async-rendering'
|
||||||
import { Route as IndexRouteImport } from './routes/index'
|
import { Route as IndexRouteImport } from './routes/index'
|
||||||
|
|
||||||
const BlankRoute = BlankRouteImport.update({
|
const BlankRoute = BlankRouteImport.update({
|
||||||
@@ -17,6 +18,11 @@ const BlankRoute = BlankRouteImport.update({
|
|||||||
path: '/blank',
|
path: '/blank',
|
||||||
getParentRoute: () => rootRouteImport,
|
getParentRoute: () => rootRouteImport,
|
||||||
} as any)
|
} as any)
|
||||||
|
const AsyncRenderingRoute = AsyncRenderingRouteImport.update({
|
||||||
|
id: '/async-rendering',
|
||||||
|
path: '/async-rendering',
|
||||||
|
getParentRoute: () => rootRouteImport,
|
||||||
|
} as any)
|
||||||
const IndexRoute = IndexRouteImport.update({
|
const IndexRoute = IndexRouteImport.update({
|
||||||
id: '/',
|
id: '/',
|
||||||
path: '/',
|
path: '/',
|
||||||
@@ -25,27 +31,31 @@ const IndexRoute = IndexRouteImport.update({
|
|||||||
|
|
||||||
export interface FileRoutesByFullPath {
|
export interface FileRoutesByFullPath {
|
||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
|
'/async-rendering': typeof AsyncRenderingRoute
|
||||||
'/blank': typeof BlankRoute
|
'/blank': typeof BlankRoute
|
||||||
}
|
}
|
||||||
export interface FileRoutesByTo {
|
export interface FileRoutesByTo {
|
||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
|
'/async-rendering': typeof AsyncRenderingRoute
|
||||||
'/blank': typeof BlankRoute
|
'/blank': typeof BlankRoute
|
||||||
}
|
}
|
||||||
export interface FileRoutesById {
|
export interface FileRoutesById {
|
||||||
__root__: typeof rootRouteImport
|
__root__: typeof rootRouteImport
|
||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
|
'/async-rendering': typeof AsyncRenderingRoute
|
||||||
'/blank': typeof BlankRoute
|
'/blank': typeof BlankRoute
|
||||||
}
|
}
|
||||||
export interface FileRouteTypes {
|
export interface FileRouteTypes {
|
||||||
fileRoutesByFullPath: FileRoutesByFullPath
|
fileRoutesByFullPath: FileRoutesByFullPath
|
||||||
fullPaths: '/' | '/blank'
|
fullPaths: '/' | '/async-rendering' | '/blank'
|
||||||
fileRoutesByTo: FileRoutesByTo
|
fileRoutesByTo: FileRoutesByTo
|
||||||
to: '/' | '/blank'
|
to: '/' | '/async-rendering' | '/blank'
|
||||||
id: '__root__' | '/' | '/blank'
|
id: '__root__' | '/' | '/async-rendering' | '/blank'
|
||||||
fileRoutesById: FileRoutesById
|
fileRoutesById: FileRoutesById
|
||||||
}
|
}
|
||||||
export interface RootRouteChildren {
|
export interface RootRouteChildren {
|
||||||
IndexRoute: typeof IndexRoute
|
IndexRoute: typeof IndexRoute
|
||||||
|
AsyncRenderingRoute: typeof AsyncRenderingRoute
|
||||||
BlankRoute: typeof BlankRoute
|
BlankRoute: typeof BlankRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +68,13 @@ declare module '@tanstack/react-router' {
|
|||||||
preLoaderRoute: typeof BlankRouteImport
|
preLoaderRoute: typeof BlankRouteImport
|
||||||
parentRoute: typeof rootRouteImport
|
parentRoute: typeof rootRouteImport
|
||||||
}
|
}
|
||||||
|
'/async-rendering': {
|
||||||
|
id: '/async-rendering'
|
||||||
|
path: '/async-rendering'
|
||||||
|
fullPath: '/async-rendering'
|
||||||
|
preLoaderRoute: typeof AsyncRenderingRouteImport
|
||||||
|
parentRoute: typeof rootRouteImport
|
||||||
|
}
|
||||||
'/': {
|
'/': {
|
||||||
id: '/'
|
id: '/'
|
||||||
path: '/'
|
path: '/'
|
||||||
@@ -70,6 +87,7 @@ declare module '@tanstack/react-router' {
|
|||||||
|
|
||||||
const rootRouteChildren: RootRouteChildren = {
|
const rootRouteChildren: RootRouteChildren = {
|
||||||
IndexRoute: IndexRoute,
|
IndexRoute: IndexRoute,
|
||||||
|
AsyncRenderingRoute: AsyncRenderingRoute,
|
||||||
BlankRoute: BlankRoute,
|
BlankRoute: BlankRoute,
|
||||||
}
|
}
|
||||||
export const routeTree = rootRouteImport
|
export const routeTree = rootRouteImport
|
||||||
|
|||||||
28
packages/example/src/routes/async-rendering.tsx
Normal file
28
packages/example/src/routes/async-rendering.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { runtime } from "@/runtime"
|
||||||
|
import { Text } from "@radix-ui/themes"
|
||||||
|
import { createFileRoute } from "@tanstack/react-router"
|
||||||
|
import { Console, Effect } from "effect"
|
||||||
|
import { Component } from "effect-fc"
|
||||||
|
|
||||||
|
|
||||||
|
const RouteComponent = Component.make(function* AsyncRendering() {
|
||||||
|
console.log("render")
|
||||||
|
const VAsyncComponent = yield* Component.useSuspenseFC(AsyncComponent)
|
||||||
|
return <>
|
||||||
|
<Text>Route component</Text>
|
||||||
|
<VAsyncComponent />
|
||||||
|
</>
|
||||||
|
}).pipe(
|
||||||
|
Component.withRuntime(runtime.context)
|
||||||
|
)
|
||||||
|
|
||||||
|
const AsyncComponent = Component.make(function* AsyncComponent() {
|
||||||
|
yield* Console.log("rendering")
|
||||||
|
yield* Effect.sleep("500 millis")
|
||||||
|
return <Text>Rendered!</Text>
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
export const Route = createFileRoute("/async-rendering")({
|
||||||
|
component: RouteComponent
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user