Skip to content

fix(detector): detect TanStack Start SSR from the Nitro import - #13960

Merged
HarshMN2345 merged 16 commits into
mainfrom
fix/issue-13912
Sep 29, 2026
Merged

HarshMN2345 merged 16 commits into
mainfrom
fix/issue-13912

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

TanStackStart::getAdapter() returned static for any config containing a prerender token, so a Nitro SSR app that prerenders a couple of routes was detected as a static export.

It now returns ssr when the config imports Nitro (nitro/vite or @tanstack/nitro-v2-vite-plugin): Nitro emits .output/server/index.mjs even when every route is prerendered, and .output is what the ssr adapter serves. Without Nitro, the existing prerender check is unchanged.

This follows SvelteKit::getAdapter(), which decides on @sveltejs/adapter-static being present in the comment-stripped config. It shares that check's trade-off: a Nitro import that isn't registered (unused, or the path inside a string or block comment) reads as ssr. getAdapter() does not confirm a server artifact; Appwrite selects the adapter from build output (see below).

Test Plan

Related PRs and Issues

No live impact today: Appwrite picks the adapter from build output (Detection::rendering()), which already sees server/index.mjs.

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? — no metadata change

…bset

A `routes` list or a `filter` inside the prerender block only prerenders
part of the site, so the server entry is still emitted and still needed.
Only a prerender block with no such narrowing is treated as static.
@ghost

ghost commented Sep 28, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The previously reported false-positive detection for an unused Nitro import still needs fixing.

TanStack Start adapter detection now returns ssr when the config contains either supported Nitro import path, even if it also contains a prerender setting. Without a Nitro path, it keeps the existing prerender-based result. The tests cover both Nitro paths and a line-commented import.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
📂 Walkthrough · 2
File Change
packages/detector/src/Detection/Framework/TanStackStart.php Checks for Nitro paths before applying the existing prerender check.
packages/detector/tests/DetectorTest.php Adds adapter assertions for Nitro configs and a commented-out import.
⏳ Still open from earlier reviews · 1

Reviewed 38b2bb3 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 1/5

[Medium risk] Changes framework detection logic for TanStack Start.

The PR does not appear safe to merge because default browser OAuth redirects can be sent to a native-only scheme, and previously reported detector misclassifications remain.

Fix All in Claude CodeFindings

  1. P1 Nested values hide routes ▶
  2. P1 Disabled prerendering selects static ▶
  3. P1 Block comments enable prerendering ▶
Fix with agent prompt
### Issue 1
packages/detector/src/Detection/Framework/TanStackStart.php:undefined-70
If a prerender block spreads an options object before `routes`, as in `prerender: { ...{ crawlLinks: true }, routes: ['/'] }`, this capture stops at the inner `}`. The detector then misses `routes` and returns `static` for a narrowed-prerender configuration, leaving the SSR misclassification this PR aims to fix. This line also adds `preg_match` expressions despite the repository directive not to add regular expressions; use string functions or an existing validator, or explain in the PR why neither works.

### Issue 2
packages/detector/src/Detection/Framework/TanStackStart.php:undefined-66
With no Nitro plugin, `prerender: { enabled: false }` now returns `static`: the replacement check recognizes `prerender: false` but not `enabled: false`. Because prerendering is disabled, this classifies an SSR build as static.

### Issue 3
packages/detector/src/Detection/Framework/TanStackStart.php:undefined-66
Block comments are no longer stripped. In a no-Nitro config using `tanstackStart()`, a disabled setting such as `/* prerender: { routes: ['/'] } */` is therefore treated as active prerendering, and `getAdapter()` returns `static` for an SSR build.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR detects Nitro-backed TanStack Start builds as SSR and adds adapter tests. Changes since the previous review also bypass the console OAuth relay in favor of native deep links for default success and failure URLs; that bypass currently applies to browser clients as well.

Reviews (8) · Last reviewed commit: "Merge branch 'main' into fix/issue-13912"

}

// A `routes` list or a `filter` narrows prerendering to part of the site, so the server entry is still built.
if (\preg_match('/\bprerender[\x27\x22]?\s*:\s*\{([^}]*)/', $stripped, $block) && \preg_match('/\b(?:routes|filter)[\x27\x22]?\s*:/', $block[1])) {

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.

P1 Nested values hide routes

If a prerender block spreads an options object before routes, as in prerender: { ...{ crawlLinks: true }, routes: ['/'] }, this capture stops at the inner }. The detector then misses routes and returns static for a narrowed-prerender configuration, leaving the SSR misclassification this PR aims to fix. This line also adds preg_match expressions despite the repository directive not to add regular expressions; use string functions or an existing validator, or explain in the PR why neither works.

Context Used: CLAUDE.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/detector/src/Detection/Framework/TanStackStart.php
Line: 70

Comment:
**Nested values hide routes**

If a prerender block spreads an options object before `routes`, as in `prerender: { ...{ crawlLinks: true }, routes: ['/'] }`, this capture stops at the inner `}`. The detector then misses `routes` and returns `static` for a narrowed-prerender configuration, leaving the SSR misclassification this PR aims to fix. This line also adds `preg_match` expressions despite the repository directive not to add regular expressions; use string functions or an existing validator, or explain in the PR why neither works.

**Context Used:** CLAUDE.md ([source](https://github.com/appwrite/appwrite/blob/main/CLAUDE.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

HarshMN2345 and others added 2 commits September 29, 2026 13:59
Nitro always emits .output/server/index.mjs, even when every route is
prerendered, so a Nitro config is ssr regardless of its prerender block.
Without Nitro, a prerendered build is served from dist/client (static)
unless prerender is disabled, including `prerender: { enabled: false }`.

Replaces the routes/filter block parsing, which missed shorthand keys,
spreads and nested objects.
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/issue-13912 (after).

Metric Before After Change
🚀 Requests/sec 175.75 194.14 🟢 +10.5%
⏱️ Latency P50 96.9 ms 89.92 ms 🟢 -7.2%
⏱️ Latency P95 233.87 ms 207.21 ms 🟢 -11.4%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 89.92 207.21 12,426 194.14 -26.66
Account 168.98 318.07 654 10.94 -47.22
TablesDB 87.12 164.17 6,758 109.25 -17.88
Storage 81.47 166.46 3,270 54.05 -27.93
Functions 130.85 249.83 1,744 29.37 -25.8

Top API waits (after)

API request Max wait (ms)
account.name.update 455.7
account.prefs.update 421.87
tablesdb.rows.update 385.68
functions.create 370.17
functions.delete 366.16

@HarshMN2345 HarshMN2345 changed the title fix(detector): treat narrowed prerender as SSR for TanStack Start fix(detector): detect TanStack Start SSR from the Nitro plugin Sep 29, 2026

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

A commented-out nitro() or a leftover import no longer selects ssr:
block comments are stripped and the check looks for the nitro() /
nitroV2Plugin() call instead of the import path. The enabled: false
check moves to string functions, leaving the existing prerender
expression untouched.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

@HarshMN2345

Copy link
Copy Markdown
Member Author

@hansi-codes Greptile flagged two cases on the previous commit. The nested-brace one (prerender: { filter: ({ path }) => …, enabled: false }) is fixed in d1a8396.

The other: a renamed Nitro import (import { nitro as serverPlugin } from 'nitro/vite' then serverPlugin()) is missed, and a string containing nitro() selects ssr. Handling the rename means either going back to checking the import path, which selects ssr for a commented-out nitro() call with its import left in place (flagged earlier on this PR), or parsing the import's local name out of the config. getAdapter() has no callers in Appwrite today. Is it fine to leave that case, or should this PR handle it?

@ghost

ghost commented Sep 29, 2026

Copy link
Copy Markdown

I was wrong to call this ready to merge earlier. The nested-brace case is addressed by the depth counter in TanStackStart.php:76–89, but the Nitro check at :69–73 still misses serverPlugin() and treats a quoted "nitro()" as a call. Both can change the result when prerendering is configured.

I’d handle those cases in this PR, since identifying an active Nitro plugin is the basis of the fix. Don’t switch to import-path detection alone: the commented-out-call test at DetectorTest.php:801 shows why an unused import is insufficient. Instead, recognize a Nitro import’s local name and check for its call outside comments and string literals; add tests for the alias and incidental-string cases. A full JavaScript parser isn’t necessary.

You’re right about current Appwrite impact: Jobs.php:664 uses build-output detection through Detection::rendering() (src/Appwrite/Deployment/Detection.php:18–32), not getAdapter(). That lowers the urgency, but doesn’t make the package method’s incorrect classifications disappear.

The Nitro check reads the name the plugin is imported under, so
`import { nitro as serverPlugin }` counts when serverPlugin() is called.
String literals are emptied before looking for the call, so text such
as 'nitro()' no longer selects ssr.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

HarshMN2345 and others added 2 commits September 29, 2026 14:51
A namespace import only counts through its own name
(nitroPlugin.nitro()), so settings.nitro() no longer selects ssr. The
call must start at an identifier boundary, so a short alias such as n
does not match inside paraglideVitePlugin().

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

Whitespace that does not separate two names is dropped before looking
for the call, so `nitro ()` and `serverPlugin\n()` count. Every import
of a Nitro module is read, not only the first. Braces inside strings no
longer end the prerender block.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

A module path counts only as `from 'nitro/vite'`, so the same text in a
string is not an import. A string's text reaches the prerender check
only when it is a key, so a route such as /docs/enabled:false is not
read as `enabled: false`. `nitro(...) {` declares a function and is not
counted as a call.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

Replaces the hand-rolled import and call parsing with the same check
SvelteKit uses for adapter-static: the Nitro package in the
comment-stripped config means ssr. Drops the enabled: false handling,
which is outside #13912.
@HarshMN2345 HarshMN2345 changed the title fix(detector): detect TanStack Start SSR from the Nitro plugin fix(detector): detect TanStack Start SSR from the Nitro import Sep 29, 2026
@HarshMN2345

Copy link
Copy Markdown
Member Author

@hansi-codes I've gone back to package-import detection in 962f39c, against your earlier suggestion, and removed the import and call parsing. Each round of edge cases (renamed imports, namespace calls, spacing, strings, method declarations) was growing a JavaScript parser inside a regex-free string heuristic, for a method with no callers in Appwrite; build-output detection stays authoritative.

The check now matches SvelteKit::getAdapter(), the detector's existing pattern: the adapter package in the comment-stripped config decides, commented-out imports included in the tests. The known gap is the same one SvelteKit accepts: a leftover Nitro import with the call removed reads as ssr, which still deploys a working site. Does that trade-off block the fix for #13912?

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · 1 blocking finding to address. Summary

@ghost

ghost commented Sep 29, 2026

Copy link
Copy Markdown

No, that trade-off doesn’t block this fix. I was too prescriptive in asking for call parsing. The current change is a small import-path check ahead of the existing prerender check (TanStackStart.php:61–74), consistent with SvelteKit::getAdapter() (SvelteKit.php:61–66). It covers both Nitro package paths and the commented-out line-import case in the tests (DetectorTest.php:803–805).

The unused-import false positive is worth documenting, but I wouldn’t claim it always deploys a working site: getAdapter() would report SSR without confirming a server artifact. In Appwrite’s current build flow, that result is not used; the adapter is selected from build output (Jobs.php:664–674, Detection.php:18–32). Given that boundary, I wouldn’t grow a JavaScript parser for this PR.

$stripped = \preg_replace('/(?<!:)\/\/[^\n]*/', '', $configContent) ?? $configContent;

// Nitro emits `.output/server/index.mjs` even when every route is prerendered.
if (\str_contains($stripped, 'nitro/vite') || \str_contains($stripped, '@tanstack/nitro-v2-vite-plugin')) {

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.

P1 Disabled prerendering selects static

With no Nitro plugin, prerender: { enabled: false } now returns static: the replacement check recognizes prerender: false but not enabled: false. Because prerendering is disabled, this classifies an SSR build as static.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/detector/src/Detection/Framework/TanStackStart.php
Line: 66

Comment:
**Disabled prerendering selects static**

With no Nitro plugin, `prerender: { enabled: false }` now returns `static`: the replacement check recognizes `prerender: false` but not `enabled: false`. Because prerendering is disabled, this classifies an SSR build as static.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same result as main: main's check also recognises only prerender: false, so this config returns static there too. #13912 is about Nitro apps reported as static; disabled prerendering without Nitro is a separate case that predates this PR, so it stays out of this change.

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.

You're right — this behavior predates the PR and is unchanged by the Nitro detection branch. Since #13912 specifically concerns Nitro configs being misclassified as static, enabled: false without Nitro is a separate follow-up rather than a blocking issue here. I'll withdraw the finding.

$stripped = \preg_replace('/(?<!:)\/\/[^\n]*/', '', $configContent) ?? $configContent;

// Nitro emits `.output/server/index.mjs` even when every route is prerendered.
if (\str_contains($stripped, 'nitro/vite') || \str_contains($stripped, '@tanstack/nitro-v2-vite-plugin')) {

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.

P1 Block comments enable prerendering

Block comments are no longer stripped. In a no-Nitro config using tanstackStart(), a disabled setting such as /* prerender: { routes: ['/'] } */ is therefore treated as active prerendering, and getAdapter() returns static for an SSR build.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/detector/src/Detection/Framework/TanStackStart.php
Line: 66

Comment:
**Block comments enable prerendering**

Block comments are no longer stripped. In a no-Nitro config using `tanstackStart()`, a disabled setting such as `/* prerender: { routes: ['/'] } */` is therefore treated as active prerendering, and `getAdapter()` returns `static` for an SSR build.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also unchanged from main, and consistent with the other detectors: Astro::getAdapter() and SvelteKit::getAdapter() strip // comments only, with the same expression. Handling block comments belongs in one change across all three, not in this fix.

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.

Agreed. This PR preserves the existing //-only stripping behavior used by TanStack Start and the other detectors, so the block-comment case is unchanged rather than introduced here. Handling block comments consistently across TanStack Start, Astro, and SvelteKit is better addressed as a separate change; no further action is needed for this PR.

@HarshMN2345

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

@HarshMN2345

Copy link
Copy Markdown
Member Author

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

@HarshMN2345
HarshMN2345 merged commit c86108b into main Sep 29, 2026
67 of 68 checks passed
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.

detector: getAdapter() reports static for an SSR app that prerenders any route

1 participant