Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-cougars-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": patch
---

Use a stable useOptimistic setter stub in React 18
7 changes: 4 additions & 3 deletions packages/react-router/lib/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ import { warnOnce } from "./server-runtime/warnings";
import type { unstable_ClientInstrumentation } from "./router/instrumentation";

/**
* Webpack can fail to compile on against react versions without this export
* complains that `startTransition` doesn't exist in `React`.
* Webpack can fail to compile against react versions without this export -
* it complains that `useOptimistic` doesn't exist in `React`.
*
* Using the string constant directly at runtime fixes the webpack build issue
* but can result in terser stripping the actual call at minification time.
Expand All @@ -90,6 +90,7 @@ import type { unstable_ClientInstrumentation } from "./router/instrumentation";
const USE_OPTIMISTIC = "useOptimistic";
// @ts-expect-error Needs React 19 types but we develop against 18
const useOptimisticImpl = React[USE_OPTIMISTIC];
const stableUseOptimisticSetter = () => undefined;

function useOptimisticSafe<T>(
val: T,
Expand All @@ -98,7 +99,7 @@ function useOptimisticSafe<T>(
// eslint-disable-next-line react-hooks/rules-of-hooks
return useOptimisticImpl(val);
} else {
return [val, () => undefined];
return [val, stableUseOptimisticSetter];
}
}

Expand Down