Skip to content

[Bug?]: client only doesn't work anymore for props.children #1427

@BierDav

Description

@BierDav

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Recently I updated from an old solidjs version to the latest also the new router. And noticed that the clientOnly method which was experimental back than doesn't work when wrapping props.children. This is my code:

Helper:

import { clientOnly } from "@solidjs/start";
import { Component } from "solid-js";

export default function clientOnlyComponent<T>(component: Component<T>) {
  return clientOnly(async () => ({ default: component }));
}

Usage:

import { useAuthSession } from "~/api";
import { Typography } from "@suid/material";
import TextMediaWrapper from "~/ui/TextMediaWrapper";
import { ParentProps, Show, Suspense } from "solid-js";
import clientOnlyComponent from "~/lib/util/clientOnlyComponent.ts";

export default function (props: ParentProps) {
  const [authSession] = useAuthSession();
  return (
    <>
      <Suspense>
        <Show
          when={authSession()}
          fallback={
            <TextMediaWrapper>
              <Typography variant={"h4"} sx={{ textAlign: "center" }}>
                Access Denied
              </Typography>
            </TextMediaWrapper>
          }
        >
          {authSession()?.isExpired
            ? clientOnlyComponent(() => props.children)({})
            : props.children}
        </Show>
      </Suspense>
    </>
  );
}

With the old <Outlet/> router, everything worked fine, but unfortunatey this implementation causes an endless loop on the browser after hydration which makes it unusable.

Expected behavior 🤔

A way to make props.children client only that doesn't cause and endless loop in the browser which completely freezes the tab.

Steps to reproduce 🕹

Steps:

  1. Copy my code
  2. Paste my code
  3. Fix syntax errors
  4. Run it ;)

You may experience it yourself in this neight little sample project. But don't be supprised that your tab freezes and you might have to force close it. I warned you 😉 https://stackblitz.com/~/github.com/BierDav/solid-start-ssr-bug

Context 🔦

I need the client only, because when the token that is stored in the request cookie is expired only the client can refresh it, and it wouldn't make sense to wait for all the unauthorized responses I would get when evaluating the ssr.

Your environment 🌎

System:
 OS: Windows

Node: v21.7.1

Packages:
 vinxi: ^0.3.10
 solid-js: ^1.8.15
 @solidjs/router: ^0.13.1
 @solidjs/start: ^0.7.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions