fix(dynamic): remove force-dynamic from routes that don't need it#888
fix(dynamic): remove force-dynamic from routes that don't need it#888waleedlatif1 merged 1 commit intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Greptile Summary
This PR removes the export const dynamic = 'force-dynamic' declaration from 11 Next.js API routes to address performance issues and infinite loops in getSession() calls. The changes enable caching for routes handling relatively stable data that doesn't require real-time updates.
The affected routes fall into several categories:
- Authentication & User Data: OAuth connections (
/api/auth/oauth/connections/route.ts) and user settings (/api/users/me/settings/route.ts) that change infrequently and involve expensive operations - Organizational Structure: Workspaces (
/api/workspaces/route.ts), folders (/api/folders/route.ts,/api/folders/[id]/route.ts), and organization routes that represent stable hierarchical data - Content Management: Templates (
/api/templates/route.ts,/api/templates/[id]/route.ts) for shared, read-heavy content - File Operations: Static file serving (
/api/files/serve/[...path]/route.ts) for immutable content - Business Data: Billing information (
/api/billing/route.ts) that tolerates brief staleness
The PR also includes an unrelated domain migration in the Helm production configuration, changing from 'simstudio.acme.com' to 'sim.acme.ai' across all service URLs and TLS configurations.
By removing force-dynamic, Next.js can now apply intelligent caching to these routes based on request parameters and session data, improving performance for expensive database queries and reducing server load.
Confidence Score: 2/5
- This PR introduces significant risks by removing dynamic rendering from authentication-sensitive routes that may serve stale or incorrect data to users
- Score reflects critical issues with session-dependent routes and write operations that should not be cached, despite the performance benefits
- Pay close attention to
/api/templates/[id]/route.ts(performs write operations on every GET),/api/workspaces/route.ts(user-specific data with side effects), and/api/templates/route.ts(user-specific isStarred field)
12 files reviewed, 1 comment
| const logger = createLogger('TemplatesAPI') | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
| export const revalidate = 0 |
There was a problem hiding this comment.
logic: Conflicting config: revalidate = 0 already disables caching, making the force-dynamic removal ineffective for performance gains.
* feat(whitelabel): add in the ability to whitelabel via envvars * restore site.webmanifest * fix(dynamic): remove force-dynamic from routes that don't need it (#888) * Reinstall dependencies * Update docs
* feat(whitelabel): add in the ability to whitelabel via envvars * restore site.webmanifest * fix(dynamic): remove force-dynamic from routes that don't need it (#888) * Reinstall dependencies * Update docs
…udioai#887) * feat(whitelabel): add in the ability to whitelabel via envvars * restore site.webmanifest * fix(dynamic): remove force-dynamic from routes that don't need it (simstudioai#888) * Reinstall dependencies * Update docs
Summary
Remove force-dynamic from nextjs routes that don't need it. This was causing detached state issues and infinite loop for
getSession()callsType of Change
Testing
Tested manually.
Checklist