BobaBoard / boba-frontend

Frontend for BobaBoard
https://www.bobaboard.com
MIT License
6 stars 11 forks source link

Cannot read properties of undefined (reading 'slug') in thread page #152

Closed essential-randomness closed 4 months ago

essential-randomness commented 5 months ago

This error has been reported multiple times and seems fairly common:

Cannot read properties of undefined (reading 'slug')
TypeError: Cannot read properties of undefined (reading 'slug')
    at useCommentOptions (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/deps/bobaboard-frontend/.next/server/pages/[boardId]/thread/[...threadId].js:428:25)
    at ThreadComment (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/deps/bobaboard-frontend/.next/server/pages/[boardId]/thread/[...threadId].js:612:19)
    at d (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:33:498)
    at bb (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:36:16)
    at b.render (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:42:43)
    at b.read (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:41:83)
    at exports.renderToString (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:52:138)
    at Object.renderPage (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/node_modules/next/dist/server/render.js:596:45)
    at Document1.getInitialProps (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/deps/bobaboard-frontend/.next/server/chunks/90.js:603:19)
    at MyDocument.getInitialProps (/nix/store/rq2406lrpipfbfx0qqgddzhv0yyraa94-boba-frontend/libexec/boba-frontend/deps/bobaboard-frontend/.next/server/pages/_document.js:43:83)

The error comes from useCommentOptions, even though it's unclear what line exact.

I suspect th way to fix it would be to use slug from usePageDetails for getLinkToComment instead of trying to access it from boardMetadata. See: https://github.com/BobaBoard/boba-frontend/blob/3aea307f2a1b8dc13b4ba53822b8391a7c457f19/src/components/options/useCommentOptions.ts#L57

In the future we should investigate why BoardMetadata disappears. I suspect it's not correctly cached long-term by react-query.