Repository navigation
fix(detector): detect TanStack Start SSR from the Nitro import - #13960
Conversation
…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.
🔵 Tier A · Mergeable after minor fixes
TanStack Start adapter detection now returns
📂 Walkthrough · 2
⏳ Still open from earlier reviews · 1
Reviewed |
|
| } | ||
|
|
||
| // 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])) { |
There was a problem hiding this comment.
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.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.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
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.
|
@hansi-codes Greptile flagged two cases on the previous commit. The nested-brace one ( The other: a renamed Nitro import ( |
|
I was wrong to call this ready to merge earlier. The nested-brace case is addressed by the depth counter in 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 You’re right about current Appwrite impact: |
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.
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().
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.
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.
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.
|
@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 |
|
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 ( The unused-import false positive is worth documenting, but I wouldn’t claim it always deploys a working site: |
| $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')) { |
There was a problem hiding this 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.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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')) { |
There was a problem hiding this 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.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@hansi-codes review |
|
@hansi-codes review |
What does this PR do?
TanStackStart::getAdapter()returnedstaticfor any config containing aprerendertoken, so a Nitro SSR app that prerenders a couple of routes was detected as a static export.It now returns
ssrwhen the config imports Nitro (nitro/viteor@tanstack/nitro-v2-vite-plugin): Nitro emits.output/server/index.mjseven when every route is prerendered, and.outputis what thessradapter serves. Without Nitro, the existing prerender check is unchanged.This follows
SvelteKit::getAdapter(), which decides on@sveltejs/adapter-staticbeing 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 asssr.getAdapter()does not confirm a server artifact; Appwrite selects the adapter from build output (see below).Test Plan
start-basicexample: with Nitro, every variant (no prerender,crawlLinksover the whole site,routes: ['/']) emits.output/server/index.mjs.jackytea/tanstack-starter/vite.config.tsfrom detector: getAdapter() reports static for an SSR app that prerenders any route #13912 now returnsssr.packages/detectorTanStack tests, PHPStan andcomposer lintpass.Related PRs and Issues
No live impact today: Appwrite picks the adapter from build output (
Detection::rendering()), which already seesserver/index.mjs.Checklist