solidjs / solid-router

A universal router for Solid inspired by Ember and React Router
MIT License
1.1k stars 137 forks source link

useIsRouting returning true from SSR and causing Suspense issues #418

Closed sabercoy closed 3 weeks ago

sabercoy commented 1 month ago

Describe the bug

In @solidjs/router 0.13.1, using useIsRouting() inside the root component would yield false now it yields true and the markup for this result is sent to the client, then when the component mounts it switches to false

export default function App() {
  return (
    <Router root={props => {
        const isRouting = useIsRouting()

        return (
          <MetaProvider>
            <Show when={isRouting()}>
              <div>LOADING...</div>
            </Show>
            <a href="/">Index</a>
            <a href="/about">About</a>
            <Suspense>{props.children}</Suspense>
          </MetaProvider>
        )
      }}
    >
      <FileRoutes />
    </Router>
  );
}

when it switches everything inside Suspense is removed from the DOM for some reason

all of this may be expected from changes in 0.13.2 and 0.13.3, but I am placing it here in case this behavior is not intentional. This makes it more difficult to have global handling for displaying a loader during routing.

Your Example Website or App

https://github.com/sabercoy/solid-start-useIsRouting

Steps to Reproduce the Bug or Issue

clone the repo, install deps, run dev

Expected behavior

I expected the behavior to remain the same as 0.13.1

Screenshots or Videos

https://github.com/solidjs/solid-router/assets/22666749/62e7351a-ddcd-45e3-b25d-fdc72e8c88e3

Platform

Additional context

No response

sabercoy commented 1 month ago

After playing with Suspense more, it looks like the issue of removing DOM elements can be fixed by wrapping {props.children} like <div>{props.children}</div> so perhaps this is some Suspense hydration issue.

But still, need to confirm if useIsRouting() should now be true on app load

ryansolid commented 3 weeks ago

I mean the error is but it still shouldn't happen. I believe it is fixed in 0.13.6 as I can't reproduce in the reproduction after upgraind. There were some missteps around 0.13.3 but I think we are back in a good spot.