Skip to content

Route with server function as loader that throws notFound crashes route on HMR #5763

@ulrichstark

Description

@ulrichstark

Which project does this relate to?

Start

Describe the bug

I have a route that declares a server function as loader and a notFoundComponent.
The server function throws notFound().

import { createFileRoute, notFound } from "@tanstack/react-router";
import { createServerFn } from "@tanstack/react-start";

const loaderServerFn = createServerFn().handler(() => {
  throw notFound();
});

export const Route = createFileRoute("/")({
  loader: async () => await loaderServerFn(),
  component: RouteComponent,
  notFoundComponent: NotFoundComponent,
});

function NotFoundComponent() {
  return <span>NotFoundComponent</span>;
}

function RouteComponent() {
  return <span>RouteComponent</span>;
}

It shows NotFoundComponent as expected when initially navigating to it. When saving the file again in VSCode and therefore triggering an hot module replacement event in the browser, the route crashes with following error:

{"isNotFound":true}

Your Example Website or App

https://github.com/ulrichstark/tanstack-repro-isNotFound-on-hmr

Steps to Reproduce the Bug or Issue

git clone https://github.com/ulrichstark/tanstack-repro-isNotFound-on-hmr
cd tanstack-repro-isNotFound-on-hmr
npm i
npx vite

Then go to /src/routes/index.tsx and hit save to trigger hmr.

Expected behavior

NotFoundComponent should still be shown after hmr.

Screenshots or Videos

No response

Platform

  • Router / Start Version: 1.134.12

Additional context

Maybe similar to #5322

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