SolidJSS
SolidJSโ€ข2y agoโ€ข
7 replies
Bersaelor

useNavigate - navigate(path) throws "computations created outside a `createRoot`" and error

Sometimes (not 100% of the time) when a user selects a new category in the UI, the following code sends
computations created outside a createRoot or render will never be disposed
and then
Uncaught (in promise) TypeError: Cannot read properties of null (reading '2')

const Home: Component = () => {
  const navigate = useNavigate()

  const setSelectedCategoryId = (id: string | undefined) => {
    const path = id || '/'
    navigate(path, { resolve: false })
  }


I have check thoroughly, all the createMemo and creatEffect are properly in Components and not in any async handlers or the like.

If I replace the navigate with window.location.replace everything works fine, but of course, then my site reloads fresh every time too:

  const setSelectedCategoryId = (id: string | undefined) => {
    const path = id || '/'
    window.location.replace(path)
    // navigate(path, { resolve: true })
  }
Screenshot_2024-02-20_at_14.10.01.png
Was this page helpful?