Evaluating the Use of a Global Runtime in a Next.js App

How stupid of an idea is it to use this everywhere in my next.js app?

import { type ConfigError, type Layer, ManagedRuntime } from 'effect'
import { MainLive } from './main-layer'

type LiveLayers = Layer.Layer.Success<typeof MainLive>
type Runtime = ManagedRuntime.ManagedRuntime<
    LiveLayers,
    ConfigError.ConfigError
>

let runtime: Runtime
export function getRuntime() {
    if (!runtime) {
        runtime = ManagedRuntime.make(MainLive)
    }
    return runtime
}

// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
declare const globalThis: {
    runtimeGlobal: Runtime
} & typeof global

runtime = globalThis.runtimeGlobal ?? getRuntime()

export default runtime

globalThis.runtimeGlobal = runtime


It's working, but I'm not sure if it makes any sense.
Was this page helpful?