Skip to content

fix(dynamic): remove force-dynamic from routes that don't need it#888

Merged
waleedlatif1 merged 1 commit intostagingfrom
fix/dynamic
Aug 6, 2025
Merged

fix(dynamic): remove force-dynamic from routes that don't need it#888
waleedlatif1 merged 1 commit intostagingfrom
fix/dynamic

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

Remove force-dynamic from nextjs routes that don't need it. This was causing detached state issues and infinite loop for getSession() calls

  1. /api/workspaces/route.ts - User workspace lists don't change frequently, expensive DB queries benefit from caching.
  2. /api/templates/route.ts - Shared templates are read-heavy, stable content that changes rarely.
  3. /api/templates/[id]/route.ts - Individual templates are static content once created.
  4. /api/users/me/settings/route.ts - User preferences change infrequently, perfect for caching.
  5. /api/organizations/[id]/route.ts - Organization details are stable, expensive queries benefit from caching.
  6. /api/organizations/[id]/workspaces/route.ts - Organization workspace lists are relatively stable with complex queries.
  7. /api/files/serve/[...path]/route.ts - File serving involves immutable content that should be cached.
  8. /api/folders/route.ts - Folder structures change rarely and represent organizational data.
  9. /api/folders/[id]/route.ts - Individual folders are structural data that doesn't change often.
  10. /api/billing/route.ts - Billing data doesn't change per-request and can tolerate brief staleness.
  11. /api/auth/oauth/connections/route.ts - OAuth connection lists change infrequently, expensive token decoding operations benefit from caching.

Type of Change

  • Bug fix

Testing

Tested manually.

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)

@vercel
Copy link

vercel bot commented Aug 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 6, 2025 1:43am
sim 🔄 Building (Inspect) Visit Preview 💬 Add feedback Aug 6, 2025 1:43am

@waleedlatif1 waleedlatif1 merged commit 1b0d304 into staging Aug 6, 2025
3 of 4 checks passed
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Edit Code Review Bot Settings | Greptile

const logger = createLogger('TemplatesAPI')

export const dynamic = 'force-dynamic'
export const revalidate = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Conflicting config: revalidate = 0 already disables caching, making the force-dynamic removal ineffective for performance gains.

waleedlatif1 added a commit that referenced this pull request Aug 6, 2025
* 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
@waleedlatif1 waleedlatif1 deleted the fix/dynamic branch August 6, 2025 02:01
waleedlatif1 added a commit that referenced this pull request Aug 6, 2025
* 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
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…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
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