blitz-js / legacy-framework

MIT License
3 stars 2 forks source link

ErrorBoundary not rendering in UI (Server Error) #364

Closed regardt-nel closed 2 years ago

regardt-nel commented 2 years ago

What is the problem?

ErrorBoundary wraps two components - one with an error. I expect the page to render the FallBackComponent I made but instead I get the following ->

image

Paste all your error logs here:

Error: Not a cool show!
    at Show (webpack-internal:///./app/components/Show.js:14:11)
    at renderWithHooks (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5280:16)
    at renderIndeterminateComponent (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5353:15)
    at renderElement (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5535:7)
    at renderNodeDestructive (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5674:11)
    at renderNode (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5790:12)
    at renderNodeDestructive (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5700:9)
    at finishClassComponent (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5310:3)
    at renderClassComponent (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5318:3)
    at renderElement (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5532:7)
Error: Not a cool show!
    at Show (webpack-internal:///./app/components/Show.js:14:11)
    at renderWithHooks (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5280:16)
    at renderIndeterminateComponent (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5353:15)
    at renderElement (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5535:7)
    at renderNodeDestructive (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5674:11)
    at renderNode (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5790:12)
    at renderNodeDestructive (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5700:9)
    at finishClassComponent (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5310:3)
    at renderClassComponent (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5318:3)
    at renderElement (/Users/regardt/Projects/errortest/node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5532:7)

Paste all relevant code snippets here:

Show.js

function Show({ showName }) {
  if (showName === "Game of Thrones") {
    throw new Error("Not a cool show!")
  }
  return <div>{showName}</div>
}

export default Show

coolshows.js

import Show from "app/components/Show"
import { ErrorBoundary, useQueryErrorResetBoundary } from "blitz"

const RootErrorFallback = () => {
  return <div>The show is not cool and therefor breaks the coolshows app.</div>
}
const CoolShows = () => {
  const { reset } = useQueryErrorResetBoundary()
  return (
    <div className="container">
      <h1>Cool Shows!</h1>
      <ErrorBoundary onReset={reset} FallbackComponent={RootErrorFallback}>
        <Show showName={"Game of Thrones"} />
        <Show showName={"Avengers"} />
      </ErrorBoundary>
    </div>
  )
}

export default CoolShows

What are detailed steps to reproduce this?

  1. Create a component with throw new error if the component prop is equal to specific text
  2. Set an ErrorBoundary with a fallback component if the components within the ErrorBoundary contain the prop that equals the error state

Run blitz -v and paste the output here:

Loaded env from /Users/regardt/Projects/errortest/.env.local
Loaded env from /Users/regardt/Projects/errortest/.env
macOS Big Sur | darwin-x64 | Node: v14.17.6

blitz: 0.44.0 (global)
blitz: 0.44.4 (local)

  Package manager: npm 
  System:
    OS: macOS 11.5.2
    CPU: (4) x64 Intel(R) Core(TM) i5-6360U CPU @ 2.00GHz
    Memory: 228.85 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 14.17.6 - ~/.nvm/versions/node/v14.17.6/bin/node
    Yarn: Not Found
    npm: 6.14.15 - ~/.nvm/versions/node/v14.17.6/bin/npm
    Watchman: Not Found
  npmPackages:
    @prisma/client: Not Found
    blitz: 0.44.4 => 0.44.4 
    prisma: Not Found
    react: 18.0.0-beta-149b420f6-20211119 => 18.0.0-beta-149b420f6-20211119 
    react-dom: 18.0.0-alpha-5ca4b0433-20211020 => 18.0.0-alpha-5ca4b0433-20211020 
    typescript: Not Found

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

image

beerose commented 2 years ago

Thanks for the detailed report! Do you remember if/when was it working as expected?

regardt-nel commented 2 years ago

Thanks for the detailed report! Do you remember if/when was it working as expected?

Hi @beerose no problem :) To answer your question - this is the first time I am implementing it.

I experimented with a couple of things. I get better results if I turn off SSR but still not as expected.

The code - please see the DynamicComponentWithNoSSR

import Show from "app/components/Show"
import { ErrorBoundary, useQueryErrorResetBoundary } from "blitz"
import { dynamic } from "blitz"

const DynamicComponentWithNoSSR = dynamic(() => import("../components/Show.js"), {
  ssr: false,
})

const RootErrorFallback = ({ error }) => {
  return <div>The show {error.nameOfShow} is not cool and therefor breaks the coolshows app.</div>
}
const CoolShows = () => {
  const { reset } = useQueryErrorResetBoundary()
  return (
    <div className="container">
      <h1>Cool Shows!</h1>
      <ErrorBoundary onReset={reset} FallbackComponent={RootErrorFallback}>
        <DynamicComponentWithNoSSR showName={"Avengers"} />
      </ErrorBoundary>
      <ErrorBoundary onReset={reset} FallbackComponent={RootErrorFallback}>
        <DynamicComponentWithNoSSR showName={"Game of Thrones"} />
      </ErrorBoundary>
    </div>
  )
}

export default CoolShows

I get the following output in the client: image

Is all off this maybe expected behaviour in development mode? I will test a built version next.

beerose commented 2 years ago

Hi @regardt-nel, I'm super sorry about the delay. I tested that and was able to trigger the error boundary (though, I might have done something differently). Were you able to check the built version?

regardt-nel commented 2 years ago

Hi Aleksandra. No problem at all! I have not checked the built version - I will do so and revert back to you.

On Thu, Dec 23, 2021 at 2:04 PM Aleksandra Sikora @.***> wrote:

Hi @regardt-nel https://github.com/regardt-nel, I'm super sorry about the delay. I tested that and was able to trigger the error boundary (though, I might have done something differently). Were you able to check the built version?

— Reply to this email directly, view it on GitHub https://github.com/blitz-js/legacy-framework/issues/364, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMEWLFKDJMI5DAOONE6IFTTUSMF6JANCNFSM5KAZA2YQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

-- Regardt Nel | Managing Director *CODESW*OP Pty (Ltd) App and Web Developers 1 Azure, Big Bay, 7441 +27 82 451 6800

beerose commented 2 years ago

Hi @regardt-nel, I tested that again, and the error overlay only shows on development. In prod, I can only see the error boundary (expected behavior). Nextjs displays the overlay on purpose, and I think there's no way to opt-out now. Here's more: https://github.com/vercel/next.js/discussions/13387.

I'm going to close the issue then, but please feel free to reopen if there are more issues.