Allow server actions on export mode #67336
artrixdotdev
started this conversation in
Ideas
Replies: 1 comment
-
yes. it is hell turning my nextjs app that uses server side features like cookies into electron desktop app. please add this feature. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
Server actions in Next.js have become a cornerstone feature, but their absence in export mode creates a significant limitation for developers building desktop applications with Tauri or Electron, or creating static sites that need dynamic functionality. Currently, the primary alternative is to bypass server actions entirely and make direct API calls to your Next.js app via things like
fetch('https://myapp.vercel.app')
. This workaround, while working completely fine, introduces unnecessary complexity and deviates from the streamlined Next.js development experience. Implementing server actions support in export mode would bridge the gap between static exports and dynamic functionality, allowing developers to leverage Next.js's powerful features while maintaining the benefits of static generation. This could significantly expand Next.js's utility across a broader range of applications, from JAMstack sites to desktop apps, aligning with the framework's goal of providing a flexible, powerful solution for diverse use cases.Proposal
Adding a
baseURL
tonext.config.js
as an optional property could be a simple solution. Here's how it might work:When someone tries to use server-side features in a static export, they'd need to add a baseURL in the config or set it as an environment variable (like NEXT_BASE_URL). Instead of calling
POST /signin
, it would usePOST ${baseURL}/signin
. This would be super helpful for folks using desktop frameworks with Next.js to create a single codebase that works as both an app and a website.For other use cases, there might be CORS issues, but those can be easily fixed by tweaking the
headers()
property in the config. This approach gives developers the flexibility to use server actions in static exports without complicating the Next.js setup too much.This can also apply to anything else that requires a direct interaction with the server and client, including
next/image
,next/link
, and whatever else might need it.I admit I don't know the Next.js codebase very well but if someone can point me to the correct files I would love to make a PR and get this working.
Beta Was this translation helpful? Give feedback.
All reactions