File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 devComponent ,
77 $PROXY ,
88 $DEVCOMP ,
9- EffectFunction
9+ EffectFunction ,
10+ onMount
1011} from "../reactive/signal.js" ;
1112import { sharedConfig , nextHydrateContext , setHydrateContext } from "./hydration.js" ;
1213import type { JSX } from "../jsx.js" ;
@@ -354,3 +355,26 @@ export function createUniqueId(): string {
354355 const ctx = sharedConfig . context ;
355356 return ctx ? `${ ctx . id } ${ ctx . count ++ } ` : `cl-${ counter ++ } ` ;
356357}
358+
359+ export function clientOnly < T extends Component < any > > (
360+ fn : ( ) => Promise < { default : T } >
361+ ) : T {
362+ const Lazy = lazy ( fn ) ;
363+ return ( ( props : any ) => {
364+ if ( sharedConfig . context ) {
365+ const [ flag , setFlag ] = createSignal ( false ) ;
366+
367+ onMount ( ( ) => {
368+ setFlag ( true ) ;
369+ } ) ;
370+
371+ return createMemo ( ( ) => {
372+ if ( flag ( ) ) {
373+ return createComponent ( Lazy , props ) ;
374+ }
375+ return undefined ;
376+ } ) ;
377+ }
378+ return createComponent ( Lazy , props ) ;
379+ } ) as unknown as T ;
380+ }
Original file line number Diff line number Diff line change @@ -613,3 +613,9 @@ export function Suspense(props: { fallback?: string; children: string }) {
613613 ctx . writeResource ( id , "$$f" ) ;
614614 return props . fallback ;
615615}
616+
617+ export function clientOnly < T extends Component < any > > (
618+ fn : ( ) => Promise < { default : T } >
619+ ) : T {
620+ return ( ( ) => undefined ) as unknown as T ;
621+ }
You can’t perform that action at this time.
0 commit comments