blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

Throwing RedirectError on server side (in queries and mutations) does not redirect on the frontend #171

Closed dineshgadge closed 2 years ago

dineshgadge commented 2 years ago

What is the problem?

https://codesandbox.io/s/fervent-morning-qtvzm

Throwing RedirectError from server (queries/mutations) does not redirect on the frontend. It seems this case is not handled, as the ErrorBoundary expects the error to have have a url property but raising RedirectError like

// app/projects/queries/getProjects.ts

resolver.pipe((input) => throw new RedirectError("/edit-profile"))

from server sets the message property to /edit-profile instead of setting url to /edit-profile leading an unhandled error where it expects a url but gets undefined/null. My use case is redirecting the user to edit-profile page if profile is not at least 50% complete if they try to access projects list page

Paste all your error logs here:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'auth')
    at Object.formatUrl (format-url.js?2477:32)
    at Object.formatWithValidation (utils.js?e766:109)
    at resolveHref (router.js?4a0b:169)
    at prepareUrlAs (router.js?4a0b:226)
    at Router.push (router.js?4a0b:490)
    at Object.instance.<computed> [as push] (router.js?9ce1:175)
    at ErrorBoundary.eval (error-boundary.js?e551:84)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (error-boundary.js?e551:11)
    at _next (error-boundary.js?e551:29)
    at eval (error-boundary.js?e551:34)
    at new Promise (<anonymous>)
    at eval (error-boundary.js?e551:26)
    at ErrorBoundary.componentDidCatch (error-boundary.js?e551:88)
    at ErrorBoundary.callback (react-dom.development.js?61bb:18669)
    at callCallback (react-dom.development.js?61bb:13146)
    at commitUpdateQueue (react-dom.development.js?61bb:13167)
    at commitLayoutEffectOnFiber (react-dom.development.js?61bb:23057)
    at commitLayoutMountEffects_complete (react-dom.development.js?61bb:24328)
    at commitLayoutEffects_begin (react-dom.development.js?61bb:24314)
    at commitLayoutEffects (react-dom.development.js?61bb:24252)
    at commitRootImpl (react-dom.development.js?61bb:26411)
    at commitRoot (react-dom.development.js?61bb:26280)
    at finishConcurrentRender (react-dom.development.js?61bb:25509)
    at performConcurrentWorkOnRoot (react-dom.development.js?61bb:25442)
    at workLoop (scheduler.development.js?1911:256)
    at flushWork (scheduler.development.js?1911:229)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js?1911:523)

Paste all relevant code snippets here:

Minimal code can be found here https://codesandbox.io/s/fervent-morning-qtvzm

// app/pages/check.tsx
import { Suspense } from "react";
import { useQuery } from "blitz";
import getHomepage from "app/home/queries/getHomepage";

const CheckComponent = () => {
  const [data, meta] = useQuery(getHomepage, {}, { suspense: true });

  console.log("data", data, "meta", meta);
  return <>Hello There 2</>;
};

const CheckPage = () => {
  return (
    <Suspense fallback={<p>Loading...</p>}>
      <CheckComponent />
    </Suspense>
  );
};
export default CheckPage;

// app/home/queries/getHomepage
import { resolver, RedirectError } from "blitz";

export default resolver.pipe((input) => {
  throw new RedirectError("/some-other-page");
});

What are detailed steps to reproduce this?

  1. Run the server with yarn dev
  2. Go to http://localhost:3000/check
  3. instead of getting redirected to /some-other-page we get an error mentioned above.

Run blitz -v and paste the output here:

blitz: 0.45.0-canary.0

Please include below any other applicable logs and screenshots that show your problem:

No response

beerose commented 2 years ago

Thanks for the issue!

dineshgadge commented 2 years ago

Discord Discussion Thread