Skip to content
Merged
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
10 changes: 9 additions & 1 deletion app/pages/[slug]/PageClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "lucide-react";
import Link from "next/link";
import React from "react";
import redirects from "../../../lib/redirects.config";

interface Props {
page: Page;
Expand Down Expand Up @@ -55,7 +56,14 @@ function ApplySpecialClass({ text }: { text: string }) {
const linkMatch = link.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
if (linkMatch) {
parts.push(
<LinkPreviewCard key={key++} href={linkMatch[2]}>
<LinkPreviewCard
key={key++}
href={linkMatch[2]}
newTab={
linkMatch[2].startsWith("https") ||
redirects[0].sources.includes(linkMatch[2])

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.

Hardcoded array index redirects[0] will cause a runtime error if the redirects array is empty. This is a critical bug that will crash the page rendering.

Confidence: 5/5

Suggested Fix
Suggested change
redirects[0].sources.includes(linkMatch[2])
redirects[0]?.sources.includes(linkMatch[2])

Use optional chaining (?.) to safely access the first redirect's sources, or better yet, check if redirects array has elements before accessing. If redirects is empty, this will return undefined which is falsy, preventing the crash.
Alternatively, consider flattening all sources from all redirects:

redirects.some(redirect => redirect.sources.includes(linkMatch[2]))
Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In app/pages/[slug]/PageClient.tsx around line 64, there's a hardcoded array access
redirects[0].sources.includes(linkMatch[2]) that will throw a runtime error if the
redirects array is empty; replace it with redirects[0]?.sources.includes(linkMatch[2])
using optional chaining, or better yet, use redirects.some(redirect =>
redirect.sources.includes(linkMatch[2])) to check all redirect sources instead of
just the first one.

}
>
{linkMatch[1]}
</LinkPreviewCard>,
);
Expand Down
25 changes: 20 additions & 5 deletions app/rules/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ShinyText from "@/components/bits/ShinyText";
import { fadeInUp, staggerContainer } from "@/lib/animations";
import { motion } from "framer-motion";
import { useEffect, useState } from "react";

const rules = [
{
Expand Down Expand Up @@ -39,7 +40,7 @@ const rules = [
number: "06",
title: "Format your code like you care",
description:
"Triple backticks exist for a reason. Pasting a wall of unformatted code and asking why it's broken is a fast way to get ignored. Wrap it, label the language, and give people enough context to actually help you.",
"Triple backticks exist for a reason. Pasting a wall of unformatted code and asking why it's broken is a fast way to get ignored. Wrap it in code block, label the language, and give people enough context to actually help you.",
},
{
number: "07",
Expand Down Expand Up @@ -110,6 +111,16 @@ const rules = [
];

export default function RulesPage() {
const [activeRule, setActiveRule] = useState("");

useEffect(() => {
const hash = window.location.hash;

if (hash) {
const id = hash.replace("#", "");
setActiveRule(id);
}
}, []);
return (
<div className="min-h-screen relative" style={{ background: "#030305" }}>
<div className="absolute inset-0 dot-bg opacity-50 pointer-events-none" />
Expand Down Expand Up @@ -239,7 +250,7 @@ export default function RulesPage() {
{rules.map((rule, i) => (
<motion.div
key={rule.number}
id={`rule-${rule.number}`}
id={`${rule.number}`}
variants={{
hidden: { opacity: 0, x: -20 },
visible: {
Expand All @@ -254,7 +265,10 @@ export default function RulesPage() {
className="relative p-6 md:p-8 overflow-hidden"
style={{
background: "rgba(7, 7, 15, 0.7)",
border: "1px solid rgba(99,102,241,0.1)",
border:
rule.number == activeRule
? "1px solid rgba(99,102,241,0.7)"
: "1px solid rgba(99,102,241,0.1)",
}}
>
{/* Corner brackets */}
Expand Down Expand Up @@ -303,8 +317,9 @@ export default function RulesPage() {

{/* Content */}
<div className="flex-1">
<h2
<a
className="font-semibold text-lg md:text-xl mb-2"
href={`#${rule.number}`}
style={{
fontFamily: "var(--font-geist-mono)",
color: "#e2e2f0",
Expand All @@ -317,7 +332,7 @@ export default function RulesPage() {
{">"}
</span>
{rule.title}
</h2>
</a>
<p
className="text-sm leading-relaxed"
style={{
Expand Down
6 changes: 4 additions & 2 deletions components/LinkPreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const previewCache = new Map<string, PreviewData | null>();

export function LinkPreviewCard({
href,
newTab = true,
children,
}: {
href: string;
newTab?: boolean;
children: React.ReactNode;
}) {
const [hovering, setHovering] = useState(false);
Expand Down Expand Up @@ -110,7 +112,7 @@ export function LinkPreviewCard({
<a
ref={anchorRef}
href={href}
target="_blank"
target={newTab ? "_blank" : "_self"}
rel="noopener noreferrer"
onMouseEnter={handleLinkEnter}
onMouseLeave={handleLinkLeave}
Expand Down Expand Up @@ -183,7 +185,7 @@ export function LinkPreviewCard({
<div className={data?.image && !imgError ? "pr-16" : ""}>
<a
href={href}
target="_blank"
target={newTab ? "_blank" : "_self"}
rel="noopener noreferrer"
className="font-semibold text-sm hover:underline block mb-1"
style={{
Expand Down
Loading
Loading