Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug?]: clientOnly inside Suspense boundary with createAsync that uses server action and cache is not rendered #1674

Open
2 tasks done
nirtamir2 opened this issue Nov 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@nirtamir2
Copy link
Contributor

nirtamir2 commented Nov 7, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

I added a stackblitz - it works there but on local env it won't work (and also not on a server).
It seems like we need to co-locate cache and use-server functions to the same file and we cannot split them.
When I declare my cache in a different file - it does not render clientOnly component.

https://stackblitz.com/edit/github-grada5-rgyttr?file=src%2Froutes%2Fabout.tsx

I'm using SolidStart and I'm trying to render component based on createAsync result. This component is wrapped with clientOnly - because it depends in the DOM.
It did not render this component.
Here is a small reproduction

server.ts

export const getData = cache(async () => {
  "use server";
  return Promise.resolve(55);
}, "tierlists");
import {getData} from "./server"
import Test from "./Test";

const TestClientOnly = clientOnly(() => import("./Test"));

export function MyComponent() {
  const a = createAsync(async () => {
    return { data: await getData() };
  });
  return (
    <Suspense>
      <Show when={a()} fallback={<div>Loading tierlist</div>}>
        {/*  This will not render anything ⚠️ only the fallback */}
        {(a) => <TestClientOnly fallback={"Fallback why?"}/>}
        {/*  This will render Test ✅*/}
        {(a) => <Test />}
      </Show>
    </Suspense>
  );

And inside ./Test.tsx

export default function Test(){
    return <div>Test</div>;
}

The result is that the TestClientOnly component does not rendered anything and goes into the fallback (if provided) to "Fallback why"

Expected behavior 🤔

The component will be shown and render (same as <Test/>)

Steps to reproduce 🕹

import Test from "./Test";

const TestClientOnly = clientOnly(() => import("./Test"));

export function MyComponent() {
  const a = createAsync(async () => {
    return { data: await getData() };
  });
  return (
    <Suspense>
      <Show when={a()} fallback={<div>Loading tierlist</div>}>
        {/*  This will not render anything ⚠️ only the fallback */}
        {(a) => <TestClientOnly fallback={"Fallback why?"}/>}
        {/*  This will render Test ✅*/}
        {(a) => <Test />}
      </Show>
    </Suspense>
  );

And inside ./Test.tsx

export default function Test(){
    return <div>Test</div>;
}

Context 🔦

I'm trying to use clientOnly component with data that comes from createAsync. It did not render the component - and it uses the fallback. But as I moved the cache and use server to a function in the same file - it did render.

Your environment 🌎

MacOS M1 Max, Node 22, pnpm, latest deps
@nirtamir2 nirtamir2 added the bug Something isn't working label Nov 7, 2024
@nirtamir2 nirtamir2 changed the title [Bug?]: clientOnly inside Suspense boundary with createAsync is not rendered [Bug?]: clientOnly inside Suspense boundary with createAsync that uses server action and cache is not rendered Nov 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant