Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/web/src/app/(main)/sheet/[moduleId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@ import { getSheetModules } from "@/data/sheet";
import { SheetModuleHeader } from "@/components/sheet/SheetModuleHeader";
import { SheetContentRenderer } from "@/components/sheet/SheetContentRenderer";
import styles from "./sheet-content.module.css";
import { Metadata } from "next";
import { capitalizeFirstLetter } from "@/lib/utils";

interface PageProps {
params: Promise<{ moduleId: string }>;
}

export async function generateMetadata({
params,
}: PageProps): Promise<Metadata> {
const { moduleId } = await params;

const sheetModules = getSheetModules();
const sheetModule = sheetModules.find((m) => m.id === moduleId);

return {
title: `${capitalizeFirstLetter(sheetModule?.id || "Modules")}: ${sheetModule?.name || ""} `,
description: `This module describes how to ${sheetModule?.name.toLowerCase()}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify potentially unsafe optional-chaining method calls in this file.
rg -nP 'sheetModule\?\.[A-Za-z0-9_]+\.[A-Za-z0-9_]+\(' apps/web/src/app/(main)/sheet/[moduleId]/page.tsx

Repository: apsinghdev/opensox

Length of output: 254


🏁 Script executed:

cat -n apps/web/src/app/\(main\)/sheet/\[moduleId\]/page.tsx | head -40

Repository: apsinghdev/opensox

Length of output: 1651


unsafe optional chaining in metadata generation can throw

Line 23 calls .toLowerCase() without continuing the optional chain. If sheetModule.name is undefined, this throws at runtime. The title on line 22 correctly uses a fallback (|| ""), but description does not.

proposed fix
-    description: `This module describes how to ${sheetModule?.name.toLowerCase()}`,
+    description: `This module describes how to ${sheetModule?.name?.toLowerCase() ?? "learn this topic"}`,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/app/`(main)/sheet/[moduleId]/page.tsx at line 23, The
description string uses sheetModule?.name.toLowerCase() which can throw if name
is undefined; update the template to safely access and lowercase the name (e.g.,
use sheetModule?.name?.toLowerCase() or provide a fallback like || ""),
mirroring the title's fallback so description becomes `This module describes how
to ${sheetModule?.name?.toLowerCase() || ""}` (or equivalent) to avoid runtime
errors in metadata generation.

};
}

export default async function SheetModulePage({ params }: PageProps) {
const { moduleId } = await params;
const sheetModules = getSheetModules();
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}

export const capitalizeFirstLetter = (word: string): string => {
return word.charAt(0).toUpperCase() + word.slice(1);
}