context
Introduction

@nimpl/context

Important: this functionality is unstable. The node.js functionality used within contexts may lose content.

Implementation of server contexts in React Server Components without switching to SSR.

Before using the library, read the Possible Issues

Previously, contexts were part of @nimpl/getters, but with the release of react 19, they were moved to a separate package.

Installation

Using npm:

npm i @nimpl/context

Stability

Package covered with tests. Tests are run on every release and every 6 hours on the latest Canary version of Next.js.

In this way, you can be sure that if there is a breaking change in Next.js, this will immediately become known. Even before the release of a stable version of Next.js.

The package uses unstable AsyncLocalStorage instead of react cache for the reason that cache from react.js works for the entire page as a whole. The current implementation allows to fully reproduce the logic of react client contexts. That is, contexts are available only inside the DOM from the provider, including for asynchronous components.

Examples

You can see examples in the package repository.

Additional

Please consider giving a star if you like it, it shows that the package is useful and helps continue work on this and other packages.

Create issues with wishes, ideas, difficulties, etc. All of them will definitely be considered and thought over.