Skip to content

Suspense don't work when switching routes #521

@FanetheDivine

Description

@FanetheDivine

Describe the bug

I create routes like this

{
        path: "/",
        component: (props) => (
          <Suspense fallback={<Loading />}>{props.children}</Suspense>
        ),
        children: [
          {
            path: "",
            component: Page,
          },
          {
            path: "test",
            component: (props) => (
              <Suspense fallback={<Loading1 />}>{props.children}</Suspense>
            ),
            children: [
              {
                path: "",
                component: Page1,
              },
            ],
          },
        ],
      }

in Page and Page1's functions, I code like this to show fallback

// src/pages/page.tsx
const Page: Component = () => {
  let num = 1;
  const [data, { refetch }] = createResource(async () => {
    await sleep(1000);
    return ++num;
  });
  return (
    <div style={{ display: "flex", gap: "4px" }}>
      home-{data()}
      <span onClick={refetch}>click to loading</span>
      <A href="https://github.com/test">to /test</A>
     {/* in src/pages/test/pages this link is to home and href is '/' */}
    </div>
  );
};

when I refech and first load Page, Suspense works
but when I go to '/test' then to '/',Suspense doesn't work
the page stay '/test' for 1s, and then turn to '/'

Your Example Website or App

https://codesandbox.io/p/devbox/428phl

Steps to Reproduce the Bug or Issue

  1. start the project
  2. click 'click to loading' and find Suspense show fallback
  3. click 'to /test' and find Suspense show fallback
  4. click 'to /' and find Suspense doesn't work.

Expected behavior

when swicthing routes. Suspense can always show fallback

Screenshots or Videos

No response

Platform

  • OS: Linux( in window docker)
  • Browser: Chrome
  • Version:
    "@solidjs/router": "^0.15.3",
    "solid-js": "^1.9.3"

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions