fix(settings): resolve deployment shape from the server, not module env - #7222
Open
TheodoreSpeaks wants to merge 2 commits into
Open
fix(settings): resolve deployment shape from the server, not module env#7222TheodoreSpeaks wants to merge 2 commits into
TheodoreSpeaks wants to merge 2 commits into
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThe PR moves hosted-deployment and billing visibility decisions to the server-produced workspace host context while retaining compatibility fallbacks.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| 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]
Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'origin/sta..." | Re-trigger Greptile
# Conflicts: # apps/sim/components/settings/navigation.test.ts
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 — sowindow.__ENVis unassigned and every read comes back undefined.isHostedandisBillingEnabledboth read false, so Sim Cloud's sidebar rendered as a self-hosted deployment: "Self hosting" appeared, while the elevenrequiresHostedsections plus Subscription disappeared.deploymentfield). Module constants stay as the fallback for a context served by an app version that predates it./settings/self-hostno 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.buildUnifiedSettingsNavigation— with the deployment filter moved into the sidebar (next torequiresHosted, its own inverse), a second env-filtered catalog was dead code and the exact foot-gun that caused this.seedWorkspaceListalready does in that file.Type of Change
Testing
Reproduced and verified in a running app with
NEXT_PUBLIC_FORCE_HOSTED=true, on the 404 document itself (wherewindow.__ENVis still unset, confirming the fix no longer depends on it):/settings/self-hoston hosted: 404 → redirects to/settings/general./settings/not-a-section: still 404s.requiresHostedsections correctly absent.bun run type-check, fullbun run lint,check:audits(33 audits), andcheck-block-registryall pass. 1349 tests across settings, sidebar, billing, workspaces, prefetch and the workspaces API.Known residual
The ten
selfHostedOverridevalues are stillNEXT_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 onceisHostedis server-resolved). Left out deliberately rather than widening the contract by ten booleans in this PR.Checklist