Skip to content

fix(start-plugin-core): keep prerender trailing slash off the query string#7838

Closed
cjsewell wants to merge 1 commit into
TanStack:mainfrom
cjsewell:fix/prerender-trailing-slash-query
Closed

fix(start-plugin-core): keep prerender trailing slash off the query string#7838
cjsewell wants to merge 1 commit into
TanStack:mainfrom
cjsewell:fix/prerender-trailing-slash-query

Conversation

@cjsewell

@cjsewell cjsewell commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

fix(start-plugin-core): keep prerender trailing slash off the query string

Summary

The prerender crawler applied withTrailingSlash to the full request path including the query string. Without ufo's respectQueryAndFragment option, withTrailingSlash appends the slash to the end of the string, so it lands inside the last search-param value rather than on the path:

withTrailingSlash('/posts?page=2')       // "/posts?page=2/"   (before)
withTrailingSlash('/posts?page=2', true) // "/posts/?page=2"   (after)

With crawlLinks enabled, this corrupts any crawled link that carries a search param and turns it into an infinite loop. Each round appends one more slash to the value. Because every URL is unique the crawler's seen set never dedups, so the queue grows without bound and the build hangs.

Change

packages/start-plugin-core/src/prerender.ts:

-          const res = await requestWithRedirects(
-            withTrailingSlash(withBase(page.path, routerBasePath)),
+          const res = await requestWithRedirects(
+            withTrailingSlash(withBase(page.path, routerBasePath), true),

Test plan

  • Prerender an app whose crawled HTML contains an <a href="/route?param=value">.
  • Before: the crawler loops on /route?param=value%2F%2F… and never finishes.
  • After: the request goes to /route/?param=value with the query preserved. The crawl then converges and dedups.

Closes #7837

Summary by CodeRabbit

  • Bug Fixes

    • Fixed prerendering so trailing slashes remain part of the URL path instead of being appended to query parameters.
    • Prevented potential infinite crawl loops when link crawling is enabled.
  • Release

    • Included in a patch release of the prerendering plugin.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 28da93e1-3e5e-42af-bf62-5ca13dd8225f

📥 Commits

Reviewing files that changed from the base of the PR and between 0b178a7 and 31ebb54.

📒 Files selected for processing (2)
  • .changeset/prerender-trailing-slash-query.md
  • packages/start-plugin-core/src/prerender.ts

📝 Walkthrough

Walkthrough

The prerender crawler now applies trailing slashes to URL paths without modifying query strings. A patch changeset documents the fix for @tanstack/start-plugin-core.

Changes

Prerender query-safe URL normalization

Layer / File(s) Summary
Preserve query boundaries during crawling
packages/start-plugin-core/src/prerender.ts, .changeset/prerender-trailing-slash-query.md
The crawl request enables query-and-fragment-aware trailing-slash handling, and a patch changeset records the correction.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: schiller-manuel

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing prerender trailing slashes on query-string URLs.
Linked Issues check ✅ Passed The code change matches issue #7837 by passing respectQueryAndFragment so the slash stays on the path and query strings are preserved.
Out of Scope Changes check ✅ Passed The PR only adds the targeted prerender fix and its changeset, with no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@LadyBluenotes

Copy link
Copy Markdown
Member

We only review implementation PRs after the underlying issue has been reproduced, triaged, and the scope has been agreed with a maintainer. Please include a minimal reproduction in the PR and wait for maintainer confirmation before submitting a fix. I’m closing this PR for now; we can revisit it once the issue is confirmed

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.

Prerender crawler corrupts query strings and loops forever when links carry search params

2 participants