Skip to content

Commit

Permalink
chore: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
magne4000 committed Dec 7, 2023
1 parent 54ea098 commit d5d58db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
22 changes: 18 additions & 4 deletions examples/basic/pages/index/+Page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Counter } from "./Counter";
import { ClientOnly } from "vike-solid/ClientOnly";

export default function Page() {
return (
Expand All @@ -7,9 +7,23 @@ export default function Page() {
This page is:
<ul>
<li>Rendered to HTML.</li>
<li>
Interactive. <Counter />
</li>

<ClientOnly load={() => import("./Counter")} fallback={<li>Waiting for client-side only component to load (quick)</li>}>
{(Counter) => <li>
Interactive 1. <Counter />
</li>}
</ClientOnly>

<ClientOnly load={async () => {
// Wasting time to show the fallback
await new Promise(resolve => setTimeout(resolve, 2000));

return import("./Counter");
}} fallback={<li>Waiting for client-side only component to load (slow)</li>}>
{(Counter) => <li>
Interactive 2. <Counter />
</li>}
</ClientOnly>
</ul>
</>
);
Expand Down
4 changes: 1 addition & 3 deletions examples/basic/pages/index/Counter.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { createSignal } from "solid-js";

export { Counter };

function Counter() {
export default function Counter() {
const [count, setCount] = createSignal(0);

return (
Expand Down
8 changes: 4 additions & 4 deletions vike-solid/components/ClientOnly.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Component, JSX } from "solid-js";
import { createEffect, createSignal, lazy, startTransition } from "solid-js";
import { createEffect, createSignal, lazy, Suspense } from "solid-js";
import { Dynamic } from "solid-js/web";

function ClientOnlyError() {
Expand All @@ -11,7 +11,7 @@ export function ClientOnly<T>(props: {
children: (Component: Component<T>) => JSX.Element
fallback: JSX.Element
}) {
const [getComponent, setComponent] = createSignal<Component<unknown>>(() => props.fallback);
const [getComponent, setComponent] = createSignal<Component<unknown> | undefined>(undefined);

createEffect(() => {
const loadComponent = () => {
Expand All @@ -28,8 +28,8 @@ export function ClientOnly<T>(props: {
setComponent(() => Component);
};

startTransition(loadComponent);
loadComponent();
});

return <Dynamic component={getComponent()} />;
return <Suspense fallback={props.fallback}><Dynamic component={getComponent()} /></Suspense>;
}

0 comments on commit d5d58db

Please sign in to comment.