Skip to content

The type definition of the context property of ClientDataFunctionArgs would need to be fixed. #13550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kazu-2020 opened this issue May 7, 2025 · 2 comments · Fixed by #13552

Comments

@kazu-2020
Copy link

I'm using React Router as a...

framework

Reproduction

The following code declares react-router.config.ts in my project.

declare module "react-router" {
  interface Future {
    unstable_middleware: false;
  }
}

In this case, the type ClientDataFunction must return context: undefined because such behaviour is commented out by packages/react-router/lib/types/route-module.ts. However, it actually returns unstable_RouterContextProvider.

/**
* When `future.unstable_middleware` is not enabled, this is undefined.
*
* When `future.unstable_middleware` is enabled, this is an instance of
* `unstable_RouterContextProvider` and can be used to access context values
* from your route middlewares. You may pass in initial context values in your
* `<HydratedRouter unstable_getContext>` prop
*/
context: unstable_RouterContextProvider;

System Info

System:
    OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) N100
    Memory: 9.13 GB / 15.40 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.11.0 - /usr/local/share/nvm/versions/node/v22.11.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.9.0 - /usr/local/share/nvm/versions/node/v22.11.0/bin/npm
    pnpm: 10.10.0 - /usr/local/share/nvm/versions/node/v22.11.0/bin/pnpm
  npmPackages:
    @react-router/fs-routes: ^7.5.2 => 7.5.2 
    @react-router/node: ^7.5.2 => 7.5.2 
    @react-router/serve: ^7.5.2 => 7.5.2 
    react-router: ^7.5.2 => 7.5.2 
    vite: ^6.3.3 => 6.3.3

Used Package Manager

npm

Expected Behavior

When I declare unstable_middleware: false in react-router.config.ts, the context property of ClientDataFunctionArgs must return context: undefined.

Actual Behavior

It returns context: unstable_RouterContextProvider.

@kazu-2020 kazu-2020 added the bug label May 7, 2025
@kazu-2020
Copy link
Author

kazu-2020 commented May 7, 2025

If the following suggested changes are acceptable, I am willing to create a PR.

/**
* When `future.unstable_middleware` is not enabled, this is undefined.
*
* When `future.unstable_middleware` is enabled, this is an instance of
* `unstable_RouterContextProvider` and can be used to access context values
* from your route middlewares. You may pass in initial context values in your
* `<HydratedRouter unstable_getContext>` prop
*/
context: unstable_RouterContextProvider;

type ClientDataFunctionArgs<T extends RouteInfo> = {
+    context: MiddlewareEnabled extends true
+    ? unstable_RouterContextProvider
+    : undefined;
-  context: unstable_RouterContextProvider;
}

@brophdawg11
Copy link
Contributor

This actually looks like a typo in the jsdocs.

Client side context was added (rfc) to support middleware but is decoupled from it so that you do not need to be enabling/using middleware to use client-side context: https://github.com/remix-run/react-router/blob/main/CHANGELOG.md#client-side-context-unstable.

Client side - you always get a context value. The conditional types are required for server-side context because it existed before so we need to change it from AppLoadContext -> RouterContextProvider.

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

Successfully merging a pull request may close this issue.

2 participants