Skip to content

Commit

Permalink
Merge pull request #88 from vikejs/brillout/dev
Browse files Browse the repository at this point in the history
fix: [clientOnly()] support non-default exports
  • Loading branch information
magne4000 authored Jun 17, 2024
2 parents 4c8f58b + 0db0561 commit caf0317
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions vike-solid/components/ClientOnly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,16 @@ export function ClientOnly<T>(props: {

// Copied from https://github.com/solidjs/solid-start/blob/2d75d5fedfd11f739b03ca34decf23865868ac09/packages/start/src/shared/clientOnly.tsx#L7
/**
* Same as `clientOnly` from solid-start
* @see {@link https://docs.solidjs.com/solid-start/reference/client/client-only}
* Load and render a component only on the client-side.
* @see {@link https://vike.dev/clientOnly}
*/
export function clientOnly<T extends Component<any>>(
fn: () => Promise<{
default: T;
}>
fn: () => Promise<{ default: T } | T>
) {
if (isServer) return (props: ComponentProps<T> & { fallback?: JSX.Element }) => props.fallback;

const [comp, setComp] = createSignal<T>();
fn().then(m => setComp(() => m.default));
fn().then(m => setComp(() => 'default' in m ? m.default : m));
return (props: ComponentProps<T>) => {
let Comp: T | undefined;
let m: boolean;
Expand Down

0 comments on commit caf0317

Please sign in to comment.