Skip to content

Conversation

@ankur-arch
Copy link
Contributor

@ankur-arch ankur-arch commented Nov 12, 2025

Summary by CodeRabbit

Chores

  • Added continuous integration checks to detect and prevent redirect loops; validation runs automatically on pull requests and main branch updates affecting redirect configurations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2025

Walkthrough

The PR introduces a GitHub Actions workflow, Node.js script, and supporting documentation to detect redirect loops in a redirects file. A new npm script and workflow configuration are added to automatically check for redirect issues on PRs and pushes.

Changes

Cohort / File(s) Summary
Redirect Loop Detection Script
scripts/check-redirect-loops.js
New Node.js script that parses static/_redirects, normalizes redirect sources, traverses redirect chains up to depth 10, and detects circular redirects, self-redirects, hash fragment loops, and excessive chain depth. Outputs results to stdout/stderr with exit codes 0 (no loops) or 1 (loops detected).
CI/CD Integration
.github/workflows/check-redirects.yml, package.json
Adds GitHub Actions workflow "Check Redirect Loops" triggered on PRs and main pushes when static/_redirects changes; runs Node script and posts PR comments on failure. Adds "check-redirects" npm script entry.
Documentation
scripts/README.md
New file documenting the check-redirect-loops.js utility, including usage instructions, checked conditions, exit codes, CI integration details, and example output scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • scripts/check-redirect-loops.js: Requires careful review of the redirect chain traversal algorithm, loop detection logic using visited sets, hash fragment normalization, and depth-limit handling to ensure correctness for various redirect patterns.
  • .github/workflows/check-redirects.yml: Verify workflow triggers (PR and push conditions on static/_redirects), Node.js version compatibility, and PR comment posting logic.
  • Edge cases: Hash fragment handling, splat pattern normalization, and the distinction between base-path and full-path loop detection deserve particular attention.

Possibly related PRs

  • fix: clear redirect loop #7250: Removes legacy anchor redirects from static/_redirects, likely eliminating redirect loops that the newly introduced detection script would have flagged.

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding a redirect loop checker utility to the codebase.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

Dangerous URL check

No absolute URLs to prisma.io/docs found.
No local URLs found.

@github-actions
Copy link
Contributor

Redirect check

This PR probably requires the following redirects to be added to static/_redirects:

  • This PR does not change any pages in a way that would require a redirect.

@cloudflare-workers-and-pages
Copy link

Deploying docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4e00bba
Status: ✅  Deploy successful!
Preview URL: https://afeabb4b.docs-51g.pages.dev
Branch Preview URL: https://redirect-loop-checker.docs-51g.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
scripts/README.md (1)

44-50: Add language specifiers to fenced code blocks.

The markdown code blocks at lines 44-50 and 53-63 are missing language specifiers, which affects syntax highlighting and accessibility.

As per coding guidelines.

Apply this diff:

 **No loops:**
-```
+```console
 🔍 Checking for redirect loops...
 
 📋 Found 538 internal redirects to check
 
 ✅ No redirect loops detected!

Loops detected:
- +console
🔍 Checking for redirect loops...

📋 Found 538 internal redirects to check

❌ Found 1 redirect loop(s):

Loop 1:
Chain: /getting-started → /docs/getting-started → /getting-started

Also applies to: 53-63

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43f7e1a and 4e00bba.

📒 Files selected for processing (4)
  • .github/workflows/check-redirects.yml (1 hunks)
  • package.json (1 hunks)
  • scripts/README.md (1 hunks)
  • scripts/check-redirect-loops.js (1 hunks)
🧰 Additional context used
🪛 LanguageTool
scripts/README.md

[uncategorized] ~39-~39: The official name of this software platform is spelled with a capital “H”.
Context: ...nthat modifystatic/_redirects See.github/workflows/check-redirects.yml` for the ...

(GITHUB)

🪛 markdownlint-cli2 (0.18.1)
scripts/README.md

44-44: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


53-53: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Check internal links
🔇 Additional comments (6)
scripts/check-redirect-loops.js (4)

1-13: LGTM! Clean setup with appropriate constants.

The shebang, imports, and constants are well-defined. The max depth of 10 is reasonable for detecting infinite loops while allowing legitimate redirect chains.


58-94: LGTM! Solid loop detection algorithm.

The redirect chain traversal correctly uses a visited set to detect cycles, handles max depth gracefully, and returns detailed loop information. The logic properly distinguishes between loops and legitimate chain endings.


96-148: LGTM! Well-structured main function with proper error handling.

The function correctly orchestrates the loop checking process, uses the checked set optimization to avoid redundant analysis, provides clear console output, and exits with appropriate status codes for CI integration.


46-51: Order-dependent behavior exists but doesn't affect loop detection currently—clarify the actual code execution.

The conditional block on lines 43-47 that adds baseSource to the redirects map never executes in practice because all base paths in the file appear as redirect sources before their hash-fragment variants (e.g., line 320 before line 322). When the hash-fragment source is processed, redirects.has(baseSource) is already true, so the assignment doesn't happen.

While the order-dependency is technically real, the script correctly detects no loops with the current file structure. The concern about detection behavior depending on redirect order would only manifest if the file were reorganized to place hash-fragment sources before their base paths. The existing implementation is safe but fragile to future edits.

package.json (1)

17-17: LGTM! Clean npm script addition.

The new check-redirects script is well-named and correctly references the loop detection script.

.github/workflows/check-redirects.yml (1)

1-39: LGTM! Well-configured CI workflow.

The workflow correctly:

  • Triggers on changes to the redirects file
  • Uses appropriate action versions
  • Matches the Node.js version requirement from package.json (>= 18.0)
  • Skips npm install appropriately since the script only uses Node.js built-ins
  • Posts helpful PR comments when loops are detected


for (const line of lines) {
// Skip comments, empty lines, and the footer
if (line.trim().startsWith('#') || line.trim() === '' || line.includes('NO REDIRECTS BELOW')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Consider more specific footer marker detection.

The condition line.includes('NO REDIRECTS BELOW') will match this text anywhere in the line. If a redirect path or comment contains this phrase, it will be incorrectly skipped.

Apply this diff to make the check more specific:

-    if (line.trim().startsWith('#') || line.trim() === '' || line.includes('NO REDIRECTS BELOW')) {
+    if (line.trim().startsWith('#') || line.trim() === '' || line.trim().includes('# NO REDIRECTS BELOW')) {

This ensures the marker is in a comment, not part of a redirect path.

🤖 Prompt for AI Agents
In scripts/check-redirect-loops.js around line 21, the current check uses
line.includes('NO REDIRECTS BELOW') which will match the phrase anywhere in the
line; change it to only detect the footer when it appears as a comment (e.g.,
after optional leading whitespace the line starts with a '#' followed by the
marker) so redirect paths or inline comments that contain the phrase are not
treated as the footer; implement this by trimming leading whitespace and testing
for a comment-start marker with the exact marker (or a regex like /^\s*#\s*NO
REDIRECTS BELOW\b/).

- Pull requests that modify `static/_redirects`
- Pushes to `main` that modify `static/_redirects`

See `.github/workflows/check-redirects.yml` for the workflow configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix capitalization of GitHub.

As per coding guidelines.

Apply this diff:

-See `.github/workflows/check-redirects.yml` for the workflow configuration.
+See `.github/workflows/check-redirects.yml` for the workflow configuration.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~39-~39: The official name of this software platform is spelled with a capital “H”.
Context: ...nthat modifystatic/_redirects See.github/workflows/check-redirects.yml` for the ...

(GITHUB)

🤖 Prompt for AI Agents
In scripts/README.md around line 39, the reference to GitHub should use the
proper capitalization; update the sentence to mention "GitHub" (capitalized)
when referring to the platform while keeping the repository path
`.github/workflows/check-redirects.yml` lowercase — e.g. reword to "See the
GitHub workflow configuration at `.github/workflows/check-redirects.yml`."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants