mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 16:09:06 +00:00
## Problem Studio sends pageview and global crash counters to the frontend metrics endpoint on non-production deployments (#54331). Docs sends neither, so there is no equivalent signal for docs previews. ## Solution Port the Studio implementation to `apps/docs`: - **Gate**: new `IS_PREVIEW` constant, true only on Vercel preview deployments of the hosted platform. It is false in production, local dev, self-hosted, and the Nimbus flavor. Docs has no long-running staging environment, so there is no staging branch in the gate. - **Sender**: `lib/frontend-metrics.ts`, the same fire-and-forget `text/plain` POST as Studio, tagged `app: 'docs'`. - **Pageview**: `usePageviewMetric` sends one count on hydration and on each pathname change. It is mounted from the root layout through a small client component. - **Crash**: `app/error.tsx` and `app/global-error.tsx` each send one `global_crash`. A given error reaches only one of the two boundaries, and a `WeakSet` counts each error object once, so effect re-runs do not double count. - **Nimbus**: docs had no client-readable Nimbus check, so the gate reads `NEXT_PUBLIC_IS_NIMBUS` (same name and semantics as Studio) and the variable is added to the docs build env in `turbo.jsonc`. No CSP change is needed because docs does not set a Content-Security-Policy. ## Additional context `NEXT_PUBLIC_IS_NIMBUS` must be set on the Nimbus docs project for the Nimbus exclusion to take effect. The metrics also require `NEXT_PUBLIC_IS_PLATFORM=true` on preview deployments. ## Review instructions 1. Open the docs preview deployment for this PR with the network tab open. 2. Load any page and confirm one POST to the metrics endpoint with `metric_name: "pageview"` and `app: "docs"`. 3. Navigate to another page client-side and confirm one more POST. Changing only the hash or search params should not send one. 4. Run `pnpm -F docs exec vitest run lib/frontend-metrics.test.ts hooks/usePageviewMetric.test.tsx`.
242 lines
8.0 KiB
JSON
242 lines
8.0 KiB
JSON
{
|
|
"$schema": "./../../node_modules/turbo/schema.json",
|
|
"extends": ["//"],
|
|
"tasks": {
|
|
// Generated artifacts are gitignored, so tasks downstream of an uncached task list the
|
|
// files it writes in `inputs` explicitly, in "jit" mode so they're hashed after that task
|
|
// runs. Otherwise a cache hit could restore output built from stale remote content.
|
|
|
|
"codegen:graphql": {
|
|
"outputs": ["__generated__/**"],
|
|
},
|
|
"codegen:examples": {
|
|
"inputs": ["$TURBO_ROOT$/examples/**"],
|
|
"outputs": ["examples/**"],
|
|
},
|
|
// Downloads the TypeDoc dumps only when they're missing, so it depends on local state
|
|
// rather than on inputs.
|
|
"codegen:references:new:ensure": {
|
|
"cache": false,
|
|
},
|
|
"codegen:references:dart": {
|
|
"outputs": ["spec/reference/dart/v2/supabase_flutter.json"],
|
|
},
|
|
"codegen:references:new": {
|
|
"dependsOn": ["codegen:references:new:ensure", "codegen:references:dart"],
|
|
"inputs": ["$TURBO_DEFAULT$", { "mode": "jit", "globs": ["spec/reference/**"] }],
|
|
"outputs": ["content/reference/**"],
|
|
},
|
|
// Shares features/docs/generated/ with build:federated-content, so only claim this
|
|
// script's own files.
|
|
"codegen:references:legacy": {
|
|
"outputs": [
|
|
"features/docs/generated/*.functions.json",
|
|
"features/docs/generated/*.sections.json",
|
|
"features/docs/generated/*.flat.json",
|
|
"features/docs/generated/*.bySlug.json",
|
|
"features/docs/generated/*.endpointsById.json",
|
|
],
|
|
},
|
|
// No script: runs both reference codegen steps.
|
|
"codegen:references": {
|
|
"dependsOn": ["codegen:references:legacy", "codegen:references:new"],
|
|
},
|
|
|
|
// Fetches remote (GitHub) content and the JSON artifacts the markdown generator reads.
|
|
// Not cached: the inputs are remote, so a cache restore could resurrect stale content.
|
|
"build:federated-content": {
|
|
"cache": false,
|
|
"env": [
|
|
"DOCS_GITHUB_APP_ID",
|
|
"DOCS_GITHUB_APP_INSTALLATION_ID",
|
|
"DOCS_GITHUB_APP_PRIVATE_KEY",
|
|
],
|
|
// Local-run fallback credentials.
|
|
"passThroughEnv": ["GH_TOKEN", "GITHUB_TOKEN"],
|
|
},
|
|
"build:guides-markdown": {
|
|
"dependsOn": ["build:federated-content"],
|
|
"inputs": [
|
|
"$TURBO_DEFAULT$",
|
|
{ "mode": "jit", "globs": ["content/guides/**", "features/docs/generated/**"] },
|
|
],
|
|
"env": [
|
|
"CI",
|
|
"NODE_ENV",
|
|
"NEXT_PUBLIC_API_URL",
|
|
"NEXT_PUBLIC_BASE_PATH",
|
|
"NEXT_PUBLIC_IS_PLATFORM",
|
|
"NEXT_PUBLIC_MISC_URL",
|
|
"NEXT_PUBLIC_VERCEL_ENV",
|
|
"VERCEL_ENV",
|
|
"VERCEL_URL",
|
|
],
|
|
"outputs": ["public/markdown/guides/**", "public/markdown/manifest.json"],
|
|
},
|
|
"build:reference-markdown": {
|
|
"dependsOn": ["codegen:references"],
|
|
"env": [
|
|
"CI",
|
|
"NODE_ENV",
|
|
"ENABLED_FEATURES_OVERRIDE_DISABLE_ALL",
|
|
"NEXT_PUBLIC_API_URL",
|
|
"NEXT_PUBLIC_BASE_PATH",
|
|
"NEXT_PUBLIC_IS_PLATFORM",
|
|
"NEXT_PUBLIC_MISC_URL",
|
|
"NEXT_PUBLIC_VERCEL_ENV",
|
|
"VERCEL_ENV",
|
|
"VERCEL_URL",
|
|
],
|
|
"outputs": ["public/markdown/reference/**"],
|
|
},
|
|
// No script: generates the guide and reference markdown under public/markdown/.
|
|
"build:markdown": {
|
|
"dependsOn": ["build:guides-markdown", "build:reference-markdown"],
|
|
},
|
|
// Lists every file generated above in public/markdown/sitemap.md.
|
|
"build:markdown-sitemap": {
|
|
"dependsOn": ["build:markdown"],
|
|
"inputs": ["$TURBO_DEFAULT$", { "mode": "jit", "globs": ["public/markdown/**"] }],
|
|
"env": ["NEXT_PUBLIC_BASE_PATH", "VERCEL_ENV", "VERCEL_URL"],
|
|
"outputs": ["public/markdown/sitemap.md"],
|
|
},
|
|
// Concatenates every file listed in the sitemap into public/markdown/full.md.
|
|
"build:markdown-full": {
|
|
"dependsOn": ["build:markdown"],
|
|
"inputs": ["$TURBO_DEFAULT$", { "mode": "jit", "globs": ["public/markdown/**"] }],
|
|
"outputs": ["public/markdown/full.md"],
|
|
},
|
|
"build:gz-archive": {
|
|
"dependsOn": ["build:markdown"],
|
|
"outputs": ["public/docs.tar.gz"],
|
|
},
|
|
"build:sitemap": {
|
|
"dependsOn": ["build:federated-content", "codegen:references"],
|
|
"inputs": ["$TURBO_DEFAULT$", { "mode": "jit", "globs": ["content/guides/**"] }],
|
|
"outputs": ["public/sitemap.xml"],
|
|
},
|
|
"redirects:generate": {
|
|
"outputs": ["lib/redirects/generated/**"],
|
|
},
|
|
|
|
"dev": {
|
|
"dependsOn": ["codegen:graphql", "codegen:examples", "codegen:references"],
|
|
},
|
|
"typecheck": {
|
|
"dependsOn": ["^typecheck", "codegen:graphql"],
|
|
},
|
|
"test": {
|
|
"dependsOn": ["codegen:examples"],
|
|
// Lets the smoke tests target a preview deploy or localhost instead of production.
|
|
"env": ["DOCS_SMOKE_URL"],
|
|
},
|
|
"test:smoke": {
|
|
"dependsOn": ["codegen:references"],
|
|
"cache": false,
|
|
"env": ["DOCS_SMOKE_URL"],
|
|
},
|
|
|
|
// Write to remote databases, so never cached.
|
|
"embeddings": {
|
|
"dependsOn": ["codegen:references"],
|
|
"cache": false,
|
|
"passThroughEnv": [
|
|
"ENABLED_FEATURES_OVERRIDE_DISABLE_ALL",
|
|
"NEXT_PUBLIC_MISC_ANON_KEY",
|
|
"NEXT_PUBLIC_MISC_URL",
|
|
"NEXT_PUBLIC_SUPABASE_URL",
|
|
"OPENAI_API_KEY",
|
|
"SUPABASE_SECRET_KEY",
|
|
],
|
|
},
|
|
"ingest:search_v2": {
|
|
"dependsOn": ["build:guides-markdown", "codegen:references"],
|
|
"cache": false,
|
|
"passThroughEnv": ["NEXT_PUBLIC_SUPABASE_URL", "SUPABASE_SECRET_KEY"],
|
|
},
|
|
"sync": {
|
|
"dependsOn": ["codegen:graphql"],
|
|
"cache": false,
|
|
"passThroughEnv": [
|
|
"NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
"NEXT_PUBLIC_SUPABASE_URL",
|
|
"SUPABASE_SECRET_KEY",
|
|
],
|
|
},
|
|
|
|
"build": {
|
|
"dependsOn": [
|
|
"^build",
|
|
"codegen:graphql",
|
|
"codegen:examples",
|
|
"codegen:references",
|
|
"build:markdown",
|
|
"build:markdown-sitemap",
|
|
"build:markdown-full",
|
|
"build:gz-archive",
|
|
"build:sitemap",
|
|
"redirects:generate",
|
|
],
|
|
"env": [
|
|
"ANALYZE",
|
|
"NEXT_PUBLIC_SUPABASE_URL",
|
|
"NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
"NEXT_PUBLIC_MISC_URL",
|
|
"NEXT_PUBLIC_MISC_ANON_KEY",
|
|
"NEXT_PUBLIC_MARKETPLACE_API_URL",
|
|
"NEXT_PUBLIC_MARKETPLACE_PUBLISHABLE_KEY",
|
|
"NODE_ENV",
|
|
"NEXT_PUBLIC_API_URL",
|
|
"NEXT_PUBLIC_BASE_PATH",
|
|
"NEXT_PUBLIC_SITE_URL",
|
|
"NEXT_PUBLIC_DEV_AUTH_PAGE",
|
|
"NEXT_PUBLIC_IS_NIMBUS",
|
|
"NEXT_PUBLIC_IS_PLATFORM",
|
|
"NEXT_PUBLIC_SENTRY_DSN",
|
|
"NEXT_PUBLIC_VERCEL_ENV",
|
|
"NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA",
|
|
"VERCEL",
|
|
"VERCEL_ENV",
|
|
"VERCEL_GIT_COMMIT_SHA",
|
|
"VERCEL_URL",
|
|
// These envs are used in the packages
|
|
"NEXT_PUBLIC_STORAGE_KEY",
|
|
"NEXT_PUBLIC_AUTH_DEBUG_KEY",
|
|
"NEXT_PUBLIC_AUTH_PERSISTED_KEY",
|
|
"NEXT_PUBLIC_AUTH_NAVIGATOR_LOCK_KEY",
|
|
"NEXT_PUBLIC_AUTH_DETECT_SESSION_IN_URL",
|
|
"NEXT_PUBLIC_GOOGLE_TAG_MANAGER_ID",
|
|
"NEXT_PUBLIC_GOTRUE_URL",
|
|
"NEXT_PUBLIC_SUPABASE_ANON_KEY",
|
|
"NEXT_PUBLIC_MCP_URL",
|
|
// These envs are technically passthrough env vars because they're only used on the server side of Nextjs
|
|
"CI",
|
|
"DOCS_GITHUB_APP_ID",
|
|
"DOCS_GITHUB_APP_INSTALLATION_ID",
|
|
"DOCS_GITHUB_APP_PRIVATE_KEY",
|
|
"DOCS_REVALIDATION_KEYS",
|
|
"DOCS_REVALIDATION_OVERRIDE_KEYS",
|
|
"ENABLED_FEATURES_OVERRIDE_DISABLE_ALL",
|
|
"GH_TOKEN",
|
|
"GITHUB_ACTIONS",
|
|
"GITHUB_TOKEN",
|
|
"LOGFLARE_INGESTION_API_KEY",
|
|
"LOGFLARE_SOURCE_TOKEN",
|
|
"OPENAI_API_KEY",
|
|
"SUPABASE_SECRET_KEY",
|
|
],
|
|
"passThroughEnv": ["SENTRY_AUTH_TOKEN"],
|
|
// Gitignored files written by the uncached fetch tasks, hashed after they run so new
|
|
// remote content invalidates the build.
|
|
"inputs": [
|
|
"$TURBO_DEFAULT$",
|
|
{
|
|
"mode": "jit",
|
|
"globs": ["content/guides/**", "features/docs/generated/**", "spec/reference/**"],
|
|
},
|
|
],
|
|
"outputs": [".next/**", "!.next/cache/**"],
|
|
},
|
|
},
|
|
}
|