Skip to content

Instantly share code, notes, and snippets.

@simonespa
Created December 11, 2024 12:08
Show Gist options
  • Select an option

  • Save simonespa/6281a00474ad737c72beb1b06bb23f29 to your computer and use it in GitHub Desktop.

Select an option

Save simonespa/6281a00474ad737c72beb1b06bb23f29 to your computer and use it in GitHub Desktop.
Next.js Questions & Features Requests

Next JS questions and features requests

Environment Variables that are "environment aware" on server and client

  • The default behaviour is as it works right now, with no environments
  • The number and names of environments are flexible and defined by the user. They can be configured in the nextjs.conf file
  • If defined, the client bundle(s)/asset(s) can refer to the environment name/label to lookup the appropriate config value. The bundle doesn't contain the environment value hardcoded but a reference to an external asset that is prefixed with the environment.
  • All of this is transparent to the user

A mechanism to read values globally and share them across multiple requests on the server-only

This has to do with the server-only feature flags/kill switches. We read the feature flags once at startup, but then we want the daemon to read the file continuously checking for changes. The value can be passed to client bundle via props (or something better?)

The values are shared on the server-side only.

Could we use the newest Node 18 feature?

Lifecycle hooks

So we can easily perform an action at the very beginning/end of all/some requests. With our monitoring work, we needed to collect information during the entire request lifecycle, by storing them in a temporary state which is unique per request, isolated, and is destroyed at the end. This should be treated with care because multiple requests may create an increase in memory, which is why the idea of doing this is for small informations. It may even have a cap in size which could be configurable globally.

Global state

How can values be set once at startup and being shared globally across the entire app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment