Skip to content

fix(settings): resolve deployment shape from the server, not module env - #7222

Open
TheodoreSpeaks wants to merge 2 commits into
stagingfrom
fix/self-host-setting
Open

fix(settings): resolve deployment shape from the server, not module env#7222
TheodoreSpeaks wants to merge 2 commits into
stagingfrom
fix/self-host-setting

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • The settings sidebar decided which sections exist from NEXT_PUBLIC_*-derived module constants. Those freeze at module init, and a 404 renders from Next's __next_error__ document, which never runs the root layout — so window.__ENV is unassigned and every read comes back undefined.
  • On any 404 page isHosted and isBillingEnabled both read false, so Sim Cloud's sidebar rendered as a self-hosted deployment: "Self hosting" appeared, while the eleven requiresHosted sections plus Subscription disappeared.
  • Both flags now come from the server-resolved workspace host context (new optional deployment field). Module constants stay as the fallback for a context served by an app version that predates it.
  • /settings/self-host no longer 404s on hosted. The catalog keeps every section this build can render, so the page gate redirects it to General like any other unavailable section; only a genuinely unknown segment still 404s.
  • Removed buildUnifiedSettingsNavigation — with the deployment filter moved into the sidebar (next to requiresHosted, its own inverse), a second env-filtered catalog was dead code and the exact foot-gun that caused this.
  • Host-context prefetch now parses through the route contract's response schema, so the SSR seed and a client refetch can't put differently-derived shapes on the same query key. Matches what seedWorkspaceList already does in that file.

Type of Change

  • Bug fix

Testing

Reproduced and verified in a running app with NEXT_PUBLIC_FORCE_HOSTED=true, on the 404 document itself (where window.__ENV is still unset, confirming the fix no longer depends on it):

before after
Subscription, BYOK, Members, Custom blocks, Permission groups, Audit logs, SSO, Session policies, Data retention, Data drains, Sim Mailer, White-labeling gone shown
Self hosting shown hidden
  • /settings/self-host on hosted: 404 → redirects to /settings/general.
  • /settings/not-a-section: still 404s.
  • Self-hosted mode re-checked unchanged: Self hosting renders with its Managed keys link, requiresHosted sections correctly absent.
  • bun run type-check, full bun run lint, check:audits (33 audits), and check-block-registry all pass. 1349 tests across settings, sidebar, billing, workspaces, prefetch and the workspaces API.

Known residual

The ten selfHostedOverride values are still NEXT_PUBLIC_*-derived module constants, so a self-hosted deployment's 404 page can still drop its enterprise rows. Hosted is fully fixed (that branch is skipped once isHosted is server-resolved). Left out deliberately rather than widening the contract by ten booleans in this PR.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

The settings sidebar decided which sections exist from `NEXT_PUBLIC_*`-derived
module constants. Those are frozen at module init, and a 404 renders from Next's
`__next_error__` document, which never runs the root layout — so `window.__ENV`
is unassigned and every read comes back undefined. On any 404 page `isHosted`
and `isBillingEnabled` both read false, and Sim Cloud's sidebar rendered as a
self-hosted deployment: "Self hosting" appeared while the eleven `requiresHosted`
sections plus Subscription vanished.

Read both from the server-resolved workspace host context instead, with the
module constants kept as a fallback for a context that predates the field.
`/settings/self-host` also no longer 404s on hosted — the catalog keeps every
section this build can render, so the page gate redirects it to General like any
other unavailable section, and only a genuinely unknown segment 404s.
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview Aug 28, 2026 8:03pm

Request Review

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR moves hosted-deployment and billing visibility decisions to the server-produced workspace host context while retaining compatibility fallbacks.

  • Adds deployment metadata to the workspace host-context contract and aligns SSR/client schema parsing.
  • Filters settings navigation from host-context deployment values.
  • Keeps unavailable settings segments in the route catalog so known sections redirect instead of rendering a 404.
  • Updates billing visibility and hosted/self-hosted routing tests.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/workspaces/host-context.ts Adds deployment and billing flags to the server-produced workspace host context.
apps/sim/lib/api/contracts/workspaces.ts Extends the host-context response schema with optional deployment metadata for rolling compatibility.
apps/sim/app/workspace/[workspaceId]/prefetch.ts Parses the SSR host-context seed through the same response schema used by client requests.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-sidebar/settings-sidebar.tsx Uses server-resolved deployment metadata to filter hosted, self-hosted, and billing navigation.
apps/sim/components/settings/navigation.ts Replaces the deployment-filtered navigation builder with an unfiltered route catalog.
apps/sim/app/workspace/[workspaceId]/settings/navigation.ts Resolves known settings segments from the unfiltered catalog so unavailable routes can redirect.
apps/sim/lib/billing/workspace-permissions.ts Determines billing-settings visibility from host-context deployment metadata with a compatibility fallback.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Env[Server deployment environment] --> Host[Workspace host-context resolver]
  Host --> Schema[Workspace host-context schema]
  Schema --> Seed[SSR React Query seed]
  Schema --> Fetch[Client refetch]
  Seed --> Sidebar[Settings sidebar]
  Fetch --> Sidebar
  Sidebar --> Filter[Deployment and billing visibility filters]
  Catalog[Unfiltered settings catalog] --> Route[Settings route resolution]
  Route --> Gate[Workspace availability gate]
  Gate -->|Available| Page[Requested settings page]
  Gate -->|Known but unavailable| General[Redirect to General]
  Route -->|Unknown segment| NotFound[404]
Loading

Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/sta..." | Re-trigger Greptile

# Conflicts:
#	apps/sim/components/settings/navigation.test.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 9 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

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.

1 participant