Skip to content

fix(web): inline the build-time site origin for the function runtime (variant) - #246

Open
damianrosellen1 wants to merge 1 commit into
variant/document-levelfrom
fix/site-origin-netlify-runtime-variant
Open

damianrosellen1 wants to merge 1 commit into
variant/document-levelfrom
fix/site-origin-netlify-runtime-variant

Conversation

@damianrosellen1

Copy link
Copy Markdown
Collaborator

Port of #245 by git cherry-pick -x, no conflicts: web/next.config.ts, web/src/utils/siteUrl.ts and packages/sanity-dataset-resolve are identical on both branches.

On Netlify, canonicals, hreflang, og:url and the sitemap fell back to http://localhost:3000 on any deploy without NEXT_PUBLIC_SITE_URL: Netlify's URL / DEPLOY_PRIME_URL exist at build but not in the function runtime that serves ISR regenerations and route handlers. next.config.ts now resolves the origin at build and inlines it as NEXT_PUBLIC_SITE_URL, and Netlify's production context always takes URL (a staging site on the development dataset serves its primary domain). Details in #245.

Verified

  • pnpm typecheck, pnpm lint on this branch.
  • Resolver with no host variables → http://localhost:3000.

Variant-Port: #245

🤖 Generated with Claude Code

`siteUrl.ts` falls back to Netlify's `URL` / `DEPLOY_PRIME_URL`, which only
exist at build. The function runtime that serves ISR regenerations and route
handlers lacks them, so canonicals and the sitemap fell back to
`http://localhost:3000` on every deploy without `NEXT_PUBLIC_SITE_URL`,
deploy previews included. `next.config.ts` now resolves the origin at build
and inlines it as `NEXT_PUBLIC_SITE_URL`.

Netlify's production context now always takes `URL`: a staging site on the
development dataset (`SANITY_STUDIO_DEPLOYMENT_TARGET=development`) serves
the primary domain, where `DEPLOY_PRIME_URL` is the `<branch>--` host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 18e6f96)

Copilot AI 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.

🟢 Approval recommended

The focused changes address the runtime fallback while preserving existing origin overrides and preview behavior, with no blocking issues identified.

No open issues 🎉

What changed in this PR

Ports #245 to the document-level variant, preserving the build-time site origin for Netlify runtime rendering instead of falling back to localhost.

Changes:

  • Inlines the resolved origin as NEXT_PUBLIC_SITE_URL through Next.js configuration.
  • Uses Netlify’s primary URL in production context, including staging sites, while preserving explicit overrides and preview behavior.
  • Updates documentation to explain the origin-selection rules.
File Description
web/​src/​utils/​siteUrl.ts Adjusts Netlify production-context origin selection and documents build-time resolution.
web/​next.config.ts Inlines the resolved site origin for runtime use.
packages/​sanity-dataset-resolve/​src/​index.ts Updates a comment describing the Netlify canonical-origin exception.

Review effort: Balanced

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