Skip to content
Merged
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
25 changes: 22 additions & 3 deletions src/lib/react-shared-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@ import * as React from 'react'

type AnyHook = (...args: any[]) => any;
type ReactSharedInternalsType = {
// React 18 and below
ReactCurrentDispatcher: {
current?: {
[name: string]: AnyHook
};
};
} | {
// React 19
H: {
[name: string]: AnyHook
} | null
}

export const ReactSharedInternals =
(React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactSharedInternalsType
export const ReactSharedInternals: ReactSharedInternalsType =
(React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED ??
(React as any).__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE ??
(React as any).__SERVER_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;

export const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher
function resolveDispatcher() {
if("ReactCurrentDispatcher" in ReactSharedInternals) {
return ReactSharedInternals.ReactCurrentDispatcher;
} else {
return Object.defineProperty({}, 'current', {
get: () => ReactSharedInternals.H ?? undefined,
set: (v) => { ReactSharedInternals.H = v },
});
}
}

export const ReactCurrentDispatcher = resolveDispatcher();
Loading