fix (audit-logs): audit logs page breaking due to react-router-dom import #1394
fix (audit-logs): audit logs page breaking due to react-router-dom import #1394paanSinghCoder merged 3 commits intomainfrom
Conversation
…with path aliasing to avoid conflict with host
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis pull request adds a navigation callback mechanism to audit logs components by propagating an Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
web/apps/admin/vite.config.ts (1)
37-40: Make the alias robust to workspace hoisting.
path.resolve(__dirname, "node_modules/react-router-dom")assumes a local node_modules folder. In pnpm/yarn workspaces, this path can be absent, causing the alias to point to a non-existent location. Consider resolving via Node’s module resolution instead.♻️ Suggested change
import path from "path"; +import { createRequire } from "module"; import { fileURLToPath } from "url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const require = createRequire(import.meta.url); +const reactRouterDomPath = require.resolve("react-router-dom"); resolve: { alias: { - "react-router-dom": path.resolve(__dirname, "node_modules/react-router-dom"), + "react-router-dom": reactRouterDomPath, }, },
Pull Request Test Coverage Report for Build 22135299149Details
💛 - Coveralls |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
web/lib/admin/views/audit-logs/sidepanel-list-link.tsx (1)
5-33: Discriminated union recommended to prevent silent non-link rendering whenisLinkis true withoutonNavigate.All current usages correctly pass
onNavigatewhen usingSidepanelListItemLink. However, the current prop design allowsisLink={true}with missingonNavigate, which silently renders as plain text instead of a link. Consider adopting the discriminated union pattern to enforce this constraint at compile time and prevent future misconfiguration:🔧 Suggested type tightening (discriminated union)
-type SidepanelListItemLinkProps = { - isLink: boolean; - children: ReactNode; - href: string; - label: string; - onNavigate?: (path: string) => void; - "data-test-id"?: string; -}; +type SidepanelListItemLinkProps = + | { + isLink: true; + children: ReactNode; + href: string; + label: string; + onNavigate: (path: string) => void; + "data-test-id"?: string; + } + | { + isLink: false; + children: ReactNode; + href: string; + label: string; + onNavigate?: never; + "data-test-id"?: string; + };
The issue
Opening the audit logs side panel caused:
Cannot destructure property 'basename' of 'h.useContext(...)' as it is null — Router context was null where expected it.
Why it happened
lib should be react-router-dom agnostic.
What the Vite config does
Removing the react-router-dom import from lib.