Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling of redirects encountered in serverLoader changes with Single Fetch #10208

Closed
rossipedia opened this issue Nov 10, 2024 · 3 comments · Fixed by #10317
Closed

handling of redirects encountered in serverLoader changes with Single Fetch #10208

rossipedia opened this issue Nov 10, 2024 · 3 comments · Fixed by #10317
Labels
awaiting release This issue has been fixed and will be released soon bug:unverified

Comments

@rossipedia
Copy link
Contributor

rossipedia commented Nov 10, 2024

Reproduction

https://github.com/rossipedia/await-single-fetch-shenanigans

https://stackblitz.com/~/rossipedia/await-single-fetch-shenanigans

System Info

System:
    OS: macOS 15.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 26.83 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.11.0 - ~/.local/state/fnm_multishells/43462_1731267897329/bin/node
    Yarn: 1.22.22 - ~/.local/state/fnm_multishells/43462_1731267897329/bin/yarn
    npm: 10.9.0 - ~/.local/state/fnm_multishells/43462_1731267897329/bin/npm
    pnpm: 9.12.0 - ~/.local/state/fnm_multishells/43462_1731267897329/bin/pnpm
    bun: 1.0.2 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 111.1.49.132
    Chrome: 130.0.6723.117
    Edge: 130.0.2849.80
    Safari: 18.1

Used Package Manager

npm

Expected Behavior

Note

I originally thought this was an issue with the <Await> component, but I've since realized that the underlying behavioral change is with serverLoader(), and I assume by extension turbo-stream

With v3_singleFetch enabled, a redirect Response received from serverLoader() should result in a rejected Promise.

Actual Behavior

With v3_singleFetch enabled, a redirect Response received from serverLoader() results in a resolved Promise.

When used with <Await>, note that the Response instance is passed to the children function if provided, which breaks the type contract for <Await>:

export function loader() {
  if (someCondition) {
    throw redirect('/');
  }

  return {
    foo: 'bar',
  };
}

export function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {
  return {
    promise: serverLoader<typeof loader>(),
  }
}

clientLoader.hydrate = true;

export default function RouteComponent() {
  const { promise } = useLoaderData<typeof clientLoader>();

  return (
    <Suspense fallback={<>Loading...</>}>
      <Await resolve={promise}>
        {/*
        Here, the typings say that data is of type `{ foo: string }`, but at runtime
        if `someCondition` is true it will be a `Response` instance with a 302 status
        and `Location` header.
        */}
        {(data) => <Render data={data} />}
      </Await>
    </Suspense>
  );
}
@rossipedia rossipedia changed the title <Await> handling of redirects changes with Single Fetch handling of redirects encountered in serverLoader changes with Single Fetch Nov 11, 2024
@brophdawg11 brophdawg11 linked a pull request Dec 9, 2024 that will close this issue
@brophdawg11 brophdawg11 added the awaiting release This issue has been fixed and will be released soon label Dec 11, 2024
@brophdawg11
Copy link
Contributor

This will be included in the next release

Copy link
Contributor

🤖 Hello there,

We just published version 2.15.2-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

🤖 Hello there,

We just published version 2.15.2 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon bug:unverified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants