Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions web/app/blog/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Metadata } from "next";
import { SiteHeader } from "../components/site-header";
import { BlogPager } from "../components/blog-pager";

export const metadata: Metadata = {
title: {
Expand All @@ -25,6 +26,7 @@ export default function BlogLayout({
<SiteHeader section="blog" />
<main className="w-full max-w-5xl mx-auto px-6 py-10">
<div className="docs-content text-[15px]">{children}</div>
<BlogPager />
</main>
</div>
);
Expand Down
36 changes: 3 additions & 33 deletions web/app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,18 @@
import type { Metadata } from "next";
import Link from "next/link";
import { blogPosts } from "../components/blog-posts";

export const metadata: Metadata = {
title: "Blog",
description: "News and updates from the cmux team",
};

const posts = [
{
slug: "cmd-shift-u",
title: "Cmd+Shift+U",
date: "2026-03-04",
summary:
"How Cmd+Shift+U navigates between finished agents across workspaces in cmux.",
},
{
slug: "zen-of-cmux",
title: "The Zen of cmux",
date: "2026-02-27",
summary:
"cmux is a primitive, not a solution. It gives you composable pieces and your workflow is up to you.",
},
{
slug: "show-hn-launch",
title: "Launching cmux on Show HN",
date: "2026-02-21",
summary:
"cmux hit #2 on Hacker News, got shared by Mitchell Hashimoto, and went viral in Japan.",
},
{
slug: "introducing-cmux",
title: "Introducing cmux",
date: "2026-02-12",
summary:
"A native macOS terminal built on Ghostty, designed for running multiple AI coding agents side by side.",
},
];

export default function BlogPage() {
return (
<>
<h1>Blog</h1>
<div className="space-y-8 mt-6">
{posts.map((post) => (
<div className="space-y-4 mt-6">
{blogPosts.map((post) => (
<article key={post.slug}>
<Link
href={`/blog/${post.slug}`}
Expand Down
43 changes: 43 additions & 0 deletions web/app/components/blog-pager.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";

import Link from "next/link";
import { usePathname } from "next/navigation";
import { blogPosts } from "./blog-posts";

export function BlogPager() {
const pathname = usePathname();
const index = blogPosts.findIndex(
(post) => `/blog/${post.slug}` === pathname
);
const prev = index > 0 ? blogPosts[index - 1] : null;
const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;

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.

P2 Badge Handle unmatched pathnames before deriving next post

findIndex returns -1 for routes that are not a specific post (for example /blog), but the current next expression treats -1 < blogPosts.length - 1 as true and sets next to blogPosts[0]. This causes the pager to render on non-post pages and can show an incorrect link whenever the pathname format does not exactly match (e.g., trailing-slash variants). Add an early index === -1 guard before computing prev/next so unmatched routes return null.

Useful? React with 👍 / 👎.

@cubic-dev-ai cubic-dev-ai Bot Mar 4, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Guard against findIndex returning -1; otherwise a non-matching pathname incorrectly shows the first post as next.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At web/app/components/blog-pager.tsx, line 13:

<comment>Guard against `findIndex` returning `-1`; otherwise a non-matching pathname incorrectly shows the first post as `next`.</comment>

<file context>
@@ -0,0 +1,43 @@
+    (post) => `/blog/${post.slug}` === pathname
+  );
+  const prev = index > 0 ? blogPosts[index - 1] : null;
+  const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
+
+  if (!prev && !next) return null;
</file context>
Suggested change
const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
const next = index >= 0 && index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
Fix with Cubic


if (!prev && !next) return null;
Comment on lines +9 to +15

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.

pager shows incorrectly on index page when findIndex returns -1

Suggested change
const index = blogPosts.findIndex(
(post) => `/blog/${post.slug}` === pathname
);
const prev = index > 0 ? blogPosts[index - 1] : null;
const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
if (!prev && !next) return null;
const index = blogPosts.findIndex(
(post) => `/blog/${post.slug}` === pathname
);
if (index === -1) return null;
const prev = index > 0 ? blogPosts[index - 1] : null;
const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;

Comment on lines +9 to +15

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard unmatched paths before deriving neighbors.

When findIndex returns -1 (e.g., on /blog), Line 13 resolves next to the first post, so the pager renders where it shouldn't. Add an early return for no-match routes.

💡 Suggested fix
 export function BlogPager() {
   const pathname = usePathname();
   const index = blogPosts.findIndex(
     (post) => `/blog/${post.slug}` === pathname
   );
+  if (index === -1) return null;
+
   const prev = index > 0 ? blogPosts[index - 1] : null;
   const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
 
   if (!prev && !next) return null;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const index = blogPosts.findIndex(
(post) => `/blog/${post.slug}` === pathname
);
const prev = index > 0 ? blogPosts[index - 1] : null;
const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
if (!prev && !next) return null;
export function BlogPager() {
const pathname = usePathname();
const index = blogPosts.findIndex(
(post) => `/blog/${post.slug}` === pathname
);
if (index === -1) return null;
const prev = index > 0 ? blogPosts[index - 1] : null;
const next = index < blogPosts.length - 1 ? blogPosts[index + 1] : null;
if (!prev && !next) return null;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/app/components/blog-pager.tsx` around lines 9 - 15, After computing index
with blogPosts.findIndex((post) => `/blog/${post.slug}` === pathname) in
blog-pager.tsx, guard the unmatched-path case by returning early when index ===
-1 so you don't derive prev/next for non-post routes; specifically, after
computing index check "if (index === -1) return null" before computing prev and
next (which reference blogPosts[index - 1] and blogPosts[index + 1]).


return (
<nav className="flex items-center justify-between mt-12 pt-6 border-t border-border text-[14px]">
{prev ? (
<Link
href={`/blog/${prev.slug}`}
className="flex items-center gap-1.5 text-muted hover:text-foreground transition-colors"
>
<span aria-hidden>&larr;</span>
{prev.title}
</Link>
) : (
<span />
)}
{next ? (
<Link
href={`/blog/${next.slug}`}
className="flex items-center gap-1.5 text-muted hover:text-foreground transition-colors"
>
{next.title}
<span aria-hidden>&rarr;</span>
</Link>
) : (
<span />
)}
</nav>
);
}
30 changes: 30 additions & 0 deletions web/app/components/blog-posts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const blogPosts = [
{
slug: "cmd-shift-u",
title: "Cmd+Shift+U",
date: "2026-03-04",
summary:
"How Cmd+Shift+U navigates between finished agents across workspaces in cmux.",
},
{
slug: "zen-of-cmux",
title: "The Zen of cmux",
date: "2026-02-27",
summary:
"cmux is a primitive, not a solution. It gives you composable pieces and your workflow is up to you.",
},
{
slug: "show-hn-launch",
title: "Launching cmux on Show HN",
date: "2026-02-21",
summary:
"cmux hit #2 on Hacker News, got shared by Mitchell Hashimoto, and went viral in Japan.",
},
{
slug: "introducing-cmux",
title: "Introducing cmux",
date: "2026-02-12",
summary:
"A native macOS terminal built on Ghostty, designed for running multiple AI coding agents side by side.",
},
];