\r\n >(): AppDispatch {\r\n const store = useStore()\r\n // @ts-ignore\r\n return store.dispatch\r\n }\r\n}\r\n\r\n/**\r\n * A hook to access the redux `dispatch` function.\r\n *\r\n * @returns {any|function} redux store's `dispatch` function\r\n *\r\n * @example\r\n *\r\n * import React, { useCallback } from 'react'\r\n * import { useDispatch } from 'react-redux'\r\n *\r\n * export const CounterComponent = ({ value }) => {\r\n * const dispatch = useDispatch()\r\n * const increaseCounter = useCallback(() => dispatch({ type: 'increase-counter' }), [])\r\n * return (\r\n * \r\n * {value}\r\n * \r\n *
\r\n * )\r\n * }\r\n */\r\nexport const useDispatch = /*#__PURE__*/ createDispatchHook()\r\n","// The primary entry point assumes we are working with React 18, and thus have\r\n// useSyncExternalStore available. We can import that directly from React itself.\r\n// The useSyncExternalStoreWithSelector has to be imported, but we can use the\r\n// non-shim version. This shaves off the byte size of the shim.\r\n\r\nimport * as React from 'react'\r\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector.js'\r\n\r\nimport { initializeUseSelector } from './hooks/useSelector'\r\nimport { initializeConnect } from './components/connect'\r\n\r\ninitializeUseSelector(useSyncExternalStoreWithSelector)\r\ninitializeConnect(React.useSyncExternalStore)\r\n\r\nexport * from './exports'\r\n","/* eslint-disable valid-jsdoc, @typescript-eslint/no-unused-vars */\r\nimport type { ComponentType } from 'react'\r\nimport { React } from '../utils/react'\r\nimport { isValidElementType, isContextConsumer } from '../utils/react-is'\r\n\r\nimport type { Store } from 'redux'\r\n\r\nimport type {\r\n ConnectedComponent,\r\n InferableComponentEnhancer,\r\n InferableComponentEnhancerWithProps,\r\n ResolveThunks,\r\n DispatchProp,\r\n ConnectPropsMaybeWithoutContext,\r\n} from '../types'\r\n\r\nimport type {\r\n MapStateToPropsParam,\r\n MapDispatchToPropsParam,\r\n MergeProps,\r\n MapDispatchToPropsNonObject,\r\n SelectorFactoryOptions,\r\n} from '../connect/selectorFactory'\r\nimport defaultSelectorFactory from '../connect/selectorFactory'\r\nimport { mapDispatchToPropsFactory } from '../connect/mapDispatchToProps'\r\nimport { mapStateToPropsFactory } from '../connect/mapStateToProps'\r\nimport { mergePropsFactory } from '../connect/mergeProps'\r\n\r\nimport type { Subscription } from '../utils/Subscription'\r\nimport { createSubscription } from '../utils/Subscription'\r\nimport { useIsomorphicLayoutEffect } from '../utils/useIsomorphicLayoutEffect'\r\nimport shallowEqual from '../utils/shallowEqual'\r\nimport hoistStatics from '../utils/hoistStatics'\r\nimport warning from '../utils/warning'\r\n\r\nimport type {\r\n ReactReduxContextValue,\r\n ReactReduxContextInstance,\r\n} from './Context'\r\nimport { ReactReduxContext } from './Context'\r\n\r\nimport type { uSES } from '../utils/useSyncExternalStore'\r\nimport { notInitialized } from '../utils/useSyncExternalStore'\r\n\r\nlet useSyncExternalStore = notInitialized as uSES\r\nexport const initializeConnect = (fn: uSES) => {\r\n useSyncExternalStore = fn\r\n}\r\n\r\n// Define some constant arrays just to avoid re-creating these\r\nconst EMPTY_ARRAY: [unknown, number] = [null, 0]\r\nconst NO_SUBSCRIPTION_ARRAY = [null, null]\r\n\r\n// Attempts to stringify whatever not-really-a-component value we were given\r\n// for logging in an error message\r\nconst stringifyComponent = (Comp: unknown) => {\r\n try {\r\n return JSON.stringify(Comp)\r\n } catch (err) {\r\n return String(Comp)\r\n }\r\n}\r\n\r\ntype EffectFunc = (...args: any[]) => void | ReturnType\r\n\r\n// This is \"just\" a `useLayoutEffect`, but with two modifications:\r\n// - we need to fall back to `useEffect` in SSR to avoid annoying warnings\r\n// - we extract this to a separate function to avoid closing over values\r\n// and causing memory leaks\r\nfunction useIsomorphicLayoutEffectWithArgs(\r\n effectFunc: EffectFunc,\r\n effectArgs: any[],\r\n dependencies?: React.DependencyList\r\n) {\r\n useIsomorphicLayoutEffect(() => effectFunc(...effectArgs), dependencies)\r\n}\r\n\r\n// Effect callback, extracted: assign the latest props values to refs for later usage\r\nfunction captureWrapperProps(\r\n lastWrapperProps: React.MutableRefObject,\r\n lastChildProps: React.MutableRefObject,\r\n renderIsScheduled: React.MutableRefObject,\r\n wrapperProps: unknown,\r\n // actualChildProps: unknown,\r\n childPropsFromStoreUpdate: React.MutableRefObject,\r\n notifyNestedSubs: () => void\r\n) {\r\n // We want to capture the wrapper props and child props we used for later comparisons\r\n lastWrapperProps.current = wrapperProps\r\n renderIsScheduled.current = false\r\n\r\n // If the render was from a store update, clear out that reference and cascade the subscriber update\r\n if (childPropsFromStoreUpdate.current) {\r\n childPropsFromStoreUpdate.current = null\r\n notifyNestedSubs()\r\n }\r\n}\r\n\r\n// Effect callback, extracted: subscribe to the Redux store or nearest connected ancestor,\r\n// check for updates after dispatched actions, and trigger re-renders.\r\nfunction subscribeUpdates(\r\n shouldHandleStateChanges: boolean,\r\n store: Store,\r\n subscription: Subscription,\r\n childPropsSelector: (state: unknown, props: unknown) => unknown,\r\n lastWrapperProps: React.MutableRefObject,\r\n lastChildProps: React.MutableRefObject,\r\n renderIsScheduled: React.MutableRefObject,\r\n isMounted: React.MutableRefObject,\r\n childPropsFromStoreUpdate: React.MutableRefObject,\r\n notifyNestedSubs: () => void,\r\n // forceComponentUpdateDispatch: React.Dispatch,\r\n additionalSubscribeListener: () => void\r\n) {\r\n // If we're not subscribed to the store, nothing to do here\r\n if (!shouldHandleStateChanges) return () => {}\r\n\r\n // Capture values for checking if and when this component unmounts\r\n let didUnsubscribe = false\r\n let lastThrownError: Error | null = null\r\n\r\n // We'll run this callback every time a store subscription update propagates to this component\r\n const checkForUpdates = () => {\r\n if (didUnsubscribe || !isMounted.current) {\r\n // Don't run stale listeners.\r\n // Redux doesn't guarantee unsubscriptions happen until next dispatch.\r\n return\r\n }\r\n\r\n // TODO We're currently calling getState ourselves here, rather than letting `uSES` do it\r\n const latestStoreState = store.getState()\r\n\r\n let newChildProps, error\r\n try {\r\n // Actually run the selector with the most recent store state and wrapper props\r\n // to determine what the child props should be\r\n newChildProps = childPropsSelector(\r\n latestStoreState,\r\n lastWrapperProps.current\r\n )\r\n } catch (e) {\r\n error = e\r\n lastThrownError = e as Error | null\r\n }\r\n\r\n if (!error) {\r\n lastThrownError = null\r\n }\r\n\r\n // If the child props haven't changed, nothing to do here - cascade the subscription update\r\n if (newChildProps === lastChildProps.current) {\r\n if (!renderIsScheduled.current) {\r\n notifyNestedSubs()\r\n }\r\n } else {\r\n // Save references to the new child props. Note that we track the \"child props from store update\"\r\n // as a ref instead of a useState/useReducer because we need a way to determine if that value has\r\n // been processed. If this went into useState/useReducer, we couldn't clear out the value without\r\n // forcing another re-render, which we don't want.\r\n lastChildProps.current = newChildProps\r\n childPropsFromStoreUpdate.current = newChildProps\r\n renderIsScheduled.current = true\r\n\r\n // TODO This is hacky and not how `uSES` is meant to be used\r\n // Trigger the React `useSyncExternalStore` subscriber\r\n additionalSubscribeListener()\r\n }\r\n }\r\n\r\n // Actually subscribe to the nearest connected ancestor (or store)\r\n subscription.onStateChange = checkForUpdates\r\n subscription.trySubscribe()\r\n\r\n // Pull data from the store after first render in case the store has\r\n // changed since we began.\r\n checkForUpdates()\r\n\r\n const unsubscribeWrapper = () => {\r\n didUnsubscribe = true\r\n subscription.tryUnsubscribe()\r\n subscription.onStateChange = null\r\n\r\n if (lastThrownError) {\r\n // It's possible that we caught an error due to a bad mapState function, but the\r\n // parent re-rendered without this component and we're about to unmount.\r\n // This shouldn't happen as long as we do top-down subscriptions correctly, but\r\n // if we ever do those wrong, this throw will surface the error in our tests.\r\n // In that case, throw the error from here so it doesn't get lost.\r\n throw lastThrownError\r\n }\r\n }\r\n\r\n return unsubscribeWrapper\r\n}\r\n\r\n// Reducer initial state creation for our update reducer\r\nconst initStateUpdates = () => EMPTY_ARRAY\r\n\r\nexport interface ConnectProps {\r\n /** A custom Context instance that the component can use to access the store from an alternate Provider using that same Context instance */\r\n context?: ReactReduxContextInstance\r\n /** A Redux store instance to be used for subscriptions instead of the store from a Provider */\r\n store?: Store\r\n}\r\n\r\ninterface InternalConnectProps extends ConnectProps {\r\n reactReduxForwardedRef?: React.ForwardedRef\r\n}\r\n\r\nfunction strictEqual(a: unknown, b: unknown) {\r\n return a === b\r\n}\r\n\r\n/**\r\n * Infers the type of props that a connector will inject into a component.\r\n */\r\nexport type ConnectedProps =\r\n TConnector extends InferableComponentEnhancerWithProps<\r\n infer TInjectedProps,\r\n any\r\n >\r\n ? unknown extends TInjectedProps\r\n ? TConnector extends InferableComponentEnhancer\r\n ? TInjectedProps\r\n : never\r\n : TInjectedProps\r\n : never\r\n\r\nexport interface ConnectOptions<\r\n State = unknown,\r\n TStateProps = {},\r\n TOwnProps = {},\r\n TMergedProps = {}\r\n> {\r\n forwardRef?: boolean\r\n context?: typeof ReactReduxContext\r\n areStatesEqual?: (\r\n nextState: State,\r\n prevState: State,\r\n nextOwnProps: TOwnProps,\r\n prevOwnProps: TOwnProps\r\n ) => boolean\r\n\r\n areOwnPropsEqual?: (\r\n nextOwnProps: TOwnProps,\r\n prevOwnProps: TOwnProps\r\n ) => boolean\r\n\r\n areStatePropsEqual?: (\r\n nextStateProps: TStateProps,\r\n prevStateProps: TStateProps\r\n ) => boolean\r\n areMergedPropsEqual?: (\r\n nextMergedProps: TMergedProps,\r\n prevMergedProps: TMergedProps\r\n ) => boolean\r\n}\r\n\r\n/**\r\n * Connects a React component to a Redux store.\r\n *\r\n * - Without arguments, just wraps the component, without changing the behavior / props\r\n *\r\n * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior\r\n * is to override ownProps (as stated in the docs), so what remains is everything that's\r\n * not a state or dispatch prop\r\n *\r\n * - When 3rd param is passed, we don't know if ownProps propagate and whether they\r\n * should be valid component props, because it depends on mergeProps implementation.\r\n * As such, it is the user's responsibility to extend ownProps interface from state or\r\n * dispatch props or both when applicable\r\n *\r\n * @param mapStateToProps\r\n * @param mapDispatchToProps\r\n * @param mergeProps\r\n * @param options\r\n */\r\nexport interface Connect {\r\n // tslint:disable:no-unnecessary-generics\r\n (): InferableComponentEnhancer\r\n\r\n /** mapState only */\r\n (\r\n mapStateToProps: MapStateToPropsParam\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapDispatch only (as a function) */\r\n (\r\n mapStateToProps: null | undefined,\r\n mapDispatchToProps: MapDispatchToPropsNonObject\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapDispatch only (as an object) */\r\n (\r\n mapStateToProps: null | undefined,\r\n mapDispatchToProps: MapDispatchToPropsParam\r\n ): InferableComponentEnhancerWithProps<\r\n ResolveThunks,\r\n TOwnProps\r\n >\r\n\r\n /** mapState and mapDispatch (as a function)*/\r\n (\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: MapDispatchToPropsNonObject\r\n ): InferableComponentEnhancerWithProps<\r\n TStateProps & TDispatchProps,\r\n TOwnProps\r\n >\r\n\r\n /** mapState and mapDispatch (nullish) */\r\n (\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: null | undefined\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapState and mapDispatch (as an object) */\r\n (\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: MapDispatchToPropsParam\r\n ): InferableComponentEnhancerWithProps<\r\n TStateProps & ResolveThunks,\r\n TOwnProps\r\n >\r\n\r\n /** mergeProps only */\r\n (\r\n mapStateToProps: null | undefined,\r\n mapDispatchToProps: null | undefined,\r\n mergeProps: MergeProps\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapState and mergeProps */\r\n <\r\n TStateProps = {},\r\n no_dispatch = {},\r\n TOwnProps = {},\r\n TMergedProps = {},\r\n State = DefaultState\r\n >(\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: null | undefined,\r\n mergeProps: MergeProps\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapDispatch (as a object) and mergeProps */\r\n (\r\n mapStateToProps: null | undefined,\r\n mapDispatchToProps: MapDispatchToPropsParam,\r\n mergeProps: MergeProps\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapState and options */\r\n (\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: null | undefined,\r\n mergeProps: null | undefined,\r\n options: ConnectOptions\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapDispatch (as a function) and options */\r\n (\r\n mapStateToProps: null | undefined,\r\n mapDispatchToProps: MapDispatchToPropsNonObject,\r\n mergeProps: null | undefined,\r\n options: ConnectOptions<{}, TStateProps, TOwnProps>\r\n ): InferableComponentEnhancerWithProps\r\n\r\n /** mapDispatch (as an object) and options*/\r\n (\r\n mapStateToProps: null | undefined,\r\n mapDispatchToProps: MapDispatchToPropsParam,\r\n mergeProps: null | undefined,\r\n options: ConnectOptions<{}, TStateProps, TOwnProps>\r\n ): InferableComponentEnhancerWithProps<\r\n ResolveThunks,\r\n TOwnProps\r\n >\r\n\r\n /** mapState, mapDispatch (as a function), and options */\r\n (\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: MapDispatchToPropsNonObject,\r\n mergeProps: null | undefined,\r\n options: ConnectOptions\r\n ): InferableComponentEnhancerWithProps<\r\n TStateProps & TDispatchProps,\r\n TOwnProps\r\n >\r\n\r\n /** mapState, mapDispatch (as an object), and options */\r\n (\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: MapDispatchToPropsParam,\r\n mergeProps: null | undefined,\r\n options: ConnectOptions\r\n ): InferableComponentEnhancerWithProps<\r\n TStateProps & ResolveThunks,\r\n TOwnProps\r\n >\r\n\r\n /** mapState, mapDispatch, mergeProps, and options */\r\n <\r\n TStateProps = {},\r\n TDispatchProps = {},\r\n TOwnProps = {},\r\n TMergedProps = {},\r\n State = DefaultState\r\n >(\r\n mapStateToProps: MapStateToPropsParam,\r\n mapDispatchToProps: MapDispatchToPropsParam,\r\n mergeProps: MergeProps<\r\n TStateProps,\r\n TDispatchProps,\r\n TOwnProps,\r\n TMergedProps\r\n >,\r\n options?: ConnectOptions\r\n ): InferableComponentEnhancerWithProps\r\n // tslint:enable:no-unnecessary-generics\r\n}\r\n\r\nlet hasWarnedAboutDeprecatedPureOption = false\r\n\r\n/**\r\n * Connects a React component to a Redux store.\r\n *\r\n * - Without arguments, just wraps the component, without changing the behavior / props\r\n *\r\n * - If 2 params are passed (3rd param, mergeProps, is skipped), default behavior\r\n * is to override ownProps (as stated in the docs), so what remains is everything that's\r\n * not a state or dispatch prop\r\n *\r\n * - When 3rd param is passed, we don't know if ownProps propagate and whether they\r\n * should be valid component props, because it depends on mergeProps implementation.\r\n * As such, it is the user's responsibility to extend ownProps interface from state or\r\n * dispatch props or both when applicable\r\n *\r\n * @param mapStateToProps A function that extracts values from state\r\n * @param mapDispatchToProps Setup for dispatching actions\r\n * @param mergeProps Optional callback to merge state and dispatch props together\r\n * @param options Options for configuring the connection\r\n *\r\n */\r\nfunction connect<\r\n TStateProps = {},\r\n TDispatchProps = {},\r\n TOwnProps = {},\r\n TMergedProps = {},\r\n State = unknown\r\n>(\r\n mapStateToProps?: MapStateToPropsParam,\r\n mapDispatchToProps?: MapDispatchToPropsParam,\r\n mergeProps?: MergeProps,\r\n {\r\n // The `pure` option has been removed, so TS doesn't like us destructuring this to check its existence.\r\n // @ts-ignore\r\n pure,\r\n areStatesEqual = strictEqual,\r\n areOwnPropsEqual = shallowEqual,\r\n areStatePropsEqual = shallowEqual,\r\n areMergedPropsEqual = shallowEqual,\r\n\r\n // use React's forwardRef to expose a ref of the wrapped component\r\n forwardRef = false,\r\n\r\n // the context consumer to use\r\n context = ReactReduxContext,\r\n }: ConnectOptions = {}\r\n): unknown {\r\n if (process.env.NODE_ENV !== 'production') {\r\n if (pure !== undefined && !hasWarnedAboutDeprecatedPureOption) {\r\n hasWarnedAboutDeprecatedPureOption = true\r\n warning(\r\n 'The `pure` option has been removed. `connect` is now always a \"pure/memoized\" component'\r\n )\r\n }\r\n }\r\n\r\n const Context = context\r\n\r\n const initMapStateToProps = mapStateToPropsFactory(mapStateToProps)\r\n const initMapDispatchToProps = mapDispatchToPropsFactory(mapDispatchToProps)\r\n const initMergeProps = mergePropsFactory(mergeProps)\r\n\r\n const shouldHandleStateChanges = Boolean(mapStateToProps)\r\n\r\n const wrapWithConnect = (\r\n WrappedComponent: ComponentType\r\n ) => {\r\n type WrappedComponentProps = TProps &\r\n ConnectPropsMaybeWithoutContext\r\n\r\n if (process.env.NODE_ENV !== 'production') {\r\n const isValid = /*#__PURE__*/ isValidElementType(WrappedComponent)\r\n if (!isValid)\r\n throw new Error(\r\n `You must pass a component to the function returned by connect. Instead received ${stringifyComponent(\r\n WrappedComponent\r\n )}`\r\n )\r\n }\r\n\r\n const wrappedComponentName =\r\n WrappedComponent.displayName || WrappedComponent.name || 'Component'\r\n\r\n const displayName = `Connect(${wrappedComponentName})`\r\n\r\n const selectorFactoryOptions: SelectorFactoryOptions<\r\n any,\r\n any,\r\n any,\r\n any,\r\n State\r\n > = {\r\n shouldHandleStateChanges,\r\n displayName,\r\n wrappedComponentName,\r\n WrappedComponent,\r\n // @ts-ignore\r\n initMapStateToProps,\r\n // @ts-ignore\r\n initMapDispatchToProps,\r\n initMergeProps,\r\n areStatesEqual,\r\n areStatePropsEqual,\r\n areOwnPropsEqual,\r\n areMergedPropsEqual,\r\n }\r\n\r\n function ConnectFunction(\r\n props: InternalConnectProps & TOwnProps\r\n ) {\r\n const [propsContext, reactReduxForwardedRef, wrapperProps] =\r\n React.useMemo(() => {\r\n // Distinguish between actual \"data\" props that were passed to the wrapper component,\r\n // and values needed to control behavior (forwarded refs, alternate context instances).\r\n // To maintain the wrapperProps object reference, memoize this destructuring.\r\n const { reactReduxForwardedRef, ...wrapperProps } = props\r\n return [props.context, reactReduxForwardedRef, wrapperProps]\r\n }, [props])\r\n\r\n const ContextToUse: ReactReduxContextInstance = React.useMemo(() => {\r\n // Users may optionally pass in a custom context instance to use instead of our ReactReduxContext.\r\n // Memoize the check that determines which context instance we should use.\r\n let ResultContext = Context\r\n if (propsContext?.Consumer) {\r\n if (process.env.NODE_ENV !== 'production') {\r\n const isValid = /*#__PURE__*/ isContextConsumer(\r\n // @ts-ignore\r\n \r\n )\r\n if (!isValid) {\r\n throw new Error(\r\n 'You must pass a valid React context consumer as `props.context`'\r\n )\r\n }\r\n ResultContext = propsContext\r\n }\r\n }\r\n return ResultContext\r\n }, [propsContext, Context])\r\n\r\n // Retrieve the store and ancestor subscription via context, if available\r\n const contextValue = React.useContext(ContextToUse)\r\n\r\n // The store _must_ exist as either a prop or in context.\r\n // We'll check to see if it _looks_ like a Redux store first.\r\n // This allows us to pass through a `store` prop that is just a plain value.\r\n const didStoreComeFromProps =\r\n Boolean(props.store) &&\r\n Boolean(props.store!.getState) &&\r\n Boolean(props.store!.dispatch)\r\n const didStoreComeFromContext =\r\n Boolean(contextValue) && Boolean(contextValue!.store)\r\n\r\n if (\r\n process.env.NODE_ENV !== 'production' &&\r\n !didStoreComeFromProps &&\r\n !didStoreComeFromContext\r\n ) {\r\n throw new Error(\r\n `Could not find \"store\" in the context of ` +\r\n `\"${displayName}\". Either wrap the root component in a , ` +\r\n `or pass a custom React context provider to and the corresponding ` +\r\n `React context consumer to ${displayName} in connect options.`\r\n )\r\n }\r\n\r\n // Based on the previous check, one of these must be true\r\n const store: Store = didStoreComeFromProps\r\n ? props.store!\r\n : contextValue!.store\r\n\r\n const getServerState = didStoreComeFromContext\r\n ? contextValue!.getServerState\r\n : store.getState\r\n\r\n const childPropsSelector = React.useMemo(() => {\r\n // The child props selector needs the store reference as an input.\r\n // Re-create this selector whenever the store changes.\r\n return defaultSelectorFactory(store.dispatch, selectorFactoryOptions)\r\n }, [store])\r\n\r\n const [subscription, notifyNestedSubs] = React.useMemo(() => {\r\n if (!shouldHandleStateChanges) return NO_SUBSCRIPTION_ARRAY\r\n\r\n // This Subscription's source should match where store came from: props vs. context. A component\r\n // connected to the store via props shouldn't use subscription from context, or vice versa.\r\n const subscription = createSubscription(\r\n store,\r\n didStoreComeFromProps ? undefined : contextValue!.subscription\r\n )\r\n\r\n // `notifyNestedSubs` is duplicated to handle the case where the component is unmounted in\r\n // the middle of the notification loop, where `subscription` will then be null. This can\r\n // probably be avoided if Subscription's listeners logic is changed to not call listeners\r\n // that have been unsubscribed in the middle of the notification loop.\r\n const notifyNestedSubs =\r\n subscription.notifyNestedSubs.bind(subscription)\r\n\r\n return [subscription, notifyNestedSubs]\r\n }, [store, didStoreComeFromProps, contextValue])\r\n\r\n // Determine what {store, subscription} value should be put into nested context, if necessary,\r\n // and memoize that value to avoid unnecessary context updates.\r\n const overriddenContextValue = React.useMemo(() => {\r\n if (didStoreComeFromProps) {\r\n // This component is directly subscribed to a store from props.\r\n // We don't want descendants reading from this store - pass down whatever\r\n // the existing context value is from the nearest connected ancestor.\r\n return contextValue!\r\n }\r\n\r\n // Otherwise, put this component's subscription instance into context, so that\r\n // connected descendants won't update until after this component is done\r\n return {\r\n ...contextValue,\r\n subscription,\r\n } as ReactReduxContextValue\r\n }, [didStoreComeFromProps, contextValue, subscription])\r\n\r\n // Set up refs to coordinate values between the subscription effect and the render logic\r\n const lastChildProps = React.useRef()\r\n const lastWrapperProps = React.useRef(wrapperProps)\r\n const childPropsFromStoreUpdate = React.useRef()\r\n const renderIsScheduled = React.useRef(false)\r\n const isProcessingDispatch = React.useRef(false)\r\n const isMounted = React.useRef(false)\r\n\r\n const latestSubscriptionCallbackError = React.useRef()\r\n\r\n useIsomorphicLayoutEffect(() => {\r\n isMounted.current = true\r\n return () => {\r\n isMounted.current = false\r\n }\r\n }, [])\r\n\r\n const actualChildPropsSelector = React.useMemo(() => {\r\n const selector = () => {\r\n // Tricky logic here:\r\n // - This render may have been triggered by a Redux store update that produced new child props\r\n // - However, we may have gotten new wrapper props after that\r\n // If we have new child props, and the same wrapper props, we know we should use the new child props as-is.\r\n // But, if we have new wrapper props, those might change the child props, so we have to recalculate things.\r\n // So, we'll use the child props from store update only if the wrapper props are the same as last time.\r\n if (\r\n childPropsFromStoreUpdate.current &&\r\n wrapperProps === lastWrapperProps.current\r\n ) {\r\n return childPropsFromStoreUpdate.current\r\n }\r\n\r\n // TODO We're reading the store directly in render() here. Bad idea?\r\n // This will likely cause Bad Things (TM) to happen in Concurrent Mode.\r\n // Note that we do this because on renders _not_ caused by store updates, we need the latest store state\r\n // to determine what the child props should be.\r\n return childPropsSelector(store.getState(), wrapperProps)\r\n }\r\n return selector\r\n }, [store, wrapperProps])\r\n\r\n // We need this to execute synchronously every time we re-render. However, React warns\r\n // about useLayoutEffect in SSR, so we try to detect environment and fall back to\r\n // just useEffect instead to avoid the warning, since neither will run anyway.\r\n\r\n const subscribeForReact = React.useMemo(() => {\r\n const subscribe = (reactListener: () => void) => {\r\n if (!subscription) {\r\n return () => {}\r\n }\r\n\r\n return subscribeUpdates(\r\n shouldHandleStateChanges,\r\n store,\r\n subscription,\r\n // @ts-ignore\r\n childPropsSelector,\r\n lastWrapperProps,\r\n lastChildProps,\r\n renderIsScheduled,\r\n isMounted,\r\n childPropsFromStoreUpdate,\r\n notifyNestedSubs,\r\n reactListener\r\n )\r\n }\r\n\r\n return subscribe\r\n }, [subscription])\r\n\r\n useIsomorphicLayoutEffectWithArgs(captureWrapperProps, [\r\n lastWrapperProps,\r\n lastChildProps,\r\n renderIsScheduled,\r\n wrapperProps,\r\n childPropsFromStoreUpdate,\r\n notifyNestedSubs,\r\n ])\r\n\r\n let actualChildProps: Record\r\n\r\n try {\r\n actualChildProps = useSyncExternalStore(\r\n // TODO We're passing through a big wrapper that does a bunch of extra side effects besides subscribing\r\n subscribeForReact,\r\n // TODO This is incredibly hacky. We've already processed the store update and calculated new child props,\r\n // TODO and we're just passing that through so it triggers a re-render for us rather than relying on `uSES`.\r\n actualChildPropsSelector,\r\n getServerState\r\n ? () => childPropsSelector(getServerState(), wrapperProps)\r\n : actualChildPropsSelector\r\n )\r\n } catch (err) {\r\n if (latestSubscriptionCallbackError.current) {\r\n ;(\r\n err as Error\r\n ).message += `\\nThe error may be correlated with this previous error:\\n${latestSubscriptionCallbackError.current.stack}\\n\\n`\r\n }\r\n\r\n throw err\r\n }\r\n\r\n useIsomorphicLayoutEffect(() => {\r\n latestSubscriptionCallbackError.current = undefined\r\n childPropsFromStoreUpdate.current = undefined\r\n lastChildProps.current = actualChildProps\r\n })\r\n\r\n // Now that all that's done, we can finally try to actually render the child component.\r\n // We memoize the elements for the rendered child component as an optimization.\r\n const renderedWrappedComponent = React.useMemo(() => {\r\n return (\r\n // @ts-ignore\r\n \r\n )\r\n }, [reactReduxForwardedRef, WrappedComponent, actualChildProps])\r\n\r\n // If React sees the exact same element reference as last time, it bails out of re-rendering\r\n // that child, same as if it was wrapped in React.memo() or returned false from shouldComponentUpdate.\r\n const renderedChild = React.useMemo(() => {\r\n if (shouldHandleStateChanges) {\r\n // If this component is subscribed to store updates, we need to pass its own\r\n // subscription instance down to our descendants. That means rendering the same\r\n // Context instance, and putting a different value into the context.\r\n return (\r\n \r\n {renderedWrappedComponent}\r\n \r\n )\r\n }\r\n\r\n return renderedWrappedComponent\r\n }, [ContextToUse, renderedWrappedComponent, overriddenContextValue])\r\n\r\n return renderedChild\r\n }\r\n\r\n const _Connect = React.memo(ConnectFunction)\r\n\r\n type ConnectedWrapperComponent = typeof _Connect & {\r\n WrappedComponent: typeof WrappedComponent\r\n }\r\n\r\n // Add a hacky cast to get the right output type\r\n const Connect = _Connect as unknown as ConnectedComponent<\r\n typeof WrappedComponent,\r\n WrappedComponentProps\r\n >\r\n Connect.WrappedComponent = WrappedComponent\r\n Connect.displayName = ConnectFunction.displayName = displayName\r\n\r\n if (forwardRef) {\r\n const _forwarded = React.forwardRef(function forwardConnectRef(\r\n props,\r\n ref\r\n ) {\r\n // @ts-ignore\r\n return \r\n })\r\n\r\n const forwarded = _forwarded as ConnectedWrapperComponent\r\n forwarded.displayName = displayName\r\n forwarded.WrappedComponent = WrappedComponent\r\n return /*#__PURE__*/ hoistStatics(forwarded, WrappedComponent)\r\n }\r\n\r\n return /*#__PURE__*/ hoistStatics(Connect, WrappedComponent)\r\n }\r\n\r\n return wrapWithConnect\r\n}\r\n\r\nexport default connect as Connect\r\n","////////////////////////////////////////////////////////////////////////////////\n//#region Types and Constants\n////////////////////////////////////////////////////////////////////////////////\n\n/**\n * Actions represent the type of change to a location value.\n */\nexport enum Action {\n /**\n * A POP indicates a change to an arbitrary index in the history stack, such\n * as a back or forward navigation. It does not describe the direction of the\n * navigation, only that the current index changed.\n *\n * Note: This is the default action for newly created history objects.\n */\n Pop = \"POP\",\n\n /**\n * A PUSH indicates a new entry being added to the history stack, such as when\n * a link is clicked and a new page loads. When this happens, all subsequent\n * entries in the stack are lost.\n */\n Push = \"PUSH\",\n\n /**\n * A REPLACE indicates the entry at the current index in the history stack\n * being replaced by a new one.\n */\n Replace = \"REPLACE\",\n}\n\n/**\n * The pathname, search, and hash values of a URL.\n */\nexport interface Path {\n /**\n * A URL pathname, beginning with a /.\n */\n pathname: string;\n\n /**\n * A URL search string, beginning with a ?.\n */\n search: string;\n\n /**\n * A URL fragment identifier, beginning with a #.\n */\n hash: string;\n}\n\n// TODO: (v7) Change the Location generic default from `any` to `unknown` and\n// remove Remix `useLocation` wrapper.\n\n/**\n * An entry in a history stack. A location contains information about the\n * URL path, as well as possibly some arbitrary state and a key.\n */\nexport interface Location extends Path {\n /**\n * A value of arbitrary data associated with this location.\n */\n state: State;\n\n /**\n * A unique string associated with this location. May be used to safely store\n * and retrieve data in some other storage API, like `localStorage`.\n *\n * Note: This value is always \"default\" on the initial location.\n */\n key: string;\n}\n\n/**\n * A change to the current location.\n */\nexport interface Update {\n /**\n * The action that triggered the change.\n */\n action: Action;\n\n /**\n * The new location.\n */\n location: Location;\n\n /**\n * The delta between this location and the former location in the history stack\n */\n delta: number | null;\n}\n\n/**\n * A function that receives notifications about location changes.\n */\nexport interface Listener {\n (update: Update): void;\n}\n\n/**\n * Describes a location that is the destination of some navigation, either via\n * `history.push` or `history.replace`. This may be either a URL or the pieces\n * of a URL path.\n */\nexport type To = string | Partial;\n\n/**\n * A history is an interface to the navigation stack. The history serves as the\n * source of truth for the current location, as well as provides a set of\n * methods that may be used to change it.\n *\n * It is similar to the DOM's `window.history` object, but with a smaller, more\n * focused API.\n */\nexport interface History {\n /**\n * The last action that modified the current location. This will always be\n * Action.Pop when a history instance is first created. This value is mutable.\n */\n readonly action: Action;\n\n /**\n * The current location. This value is mutable.\n */\n readonly location: Location;\n\n /**\n * Returns a valid href for the given `to` value that may be used as\n * the value of an attribute.\n *\n * @param to - The destination URL\n */\n createHref(to: To): string;\n\n /**\n * Returns a URL for the given `to` value\n *\n * @param to - The destination URL\n */\n createURL(to: To): URL;\n\n /**\n * Encode a location the same way window.history would do (no-op for memory\n * history) so we ensure our PUSH/REPLACE navigations for data routers\n * behave the same as POP\n *\n * @param to Unencoded path\n */\n encodeLocation(to: To): Path;\n\n /**\n * Pushes a new location onto the history stack, increasing its length by one.\n * If there were any entries in the stack after the current one, they are\n * lost.\n *\n * @param to - The new URL\n * @param state - Data to associate with the new location\n */\n push(to: To, state?: any): void;\n\n /**\n * Replaces the current location in the history stack with a new one. The\n * location that was replaced will no longer be available.\n *\n * @param to - The new URL\n * @param state - Data to associate with the new location\n */\n replace(to: To, state?: any): void;\n\n /**\n * Navigates `n` entries backward/forward in the history stack relative to the\n * current index. For example, a \"back\" navigation would use go(-1).\n *\n * @param delta - The delta in the stack index\n */\n go(delta: number): void;\n\n /**\n * Sets up a listener that will be called whenever the current location\n * changes.\n *\n * @param listener - A function that will be called when the location changes\n * @returns unlisten - A function that may be used to stop listening\n */\n listen(listener: Listener): () => void;\n}\n\ntype HistoryState = {\n usr: any;\n key?: string;\n idx: number;\n};\n\nconst PopStateEventType = \"popstate\";\n//#endregion\n\n////////////////////////////////////////////////////////////////////////////////\n//#region Memory History\n////////////////////////////////////////////////////////////////////////////////\n\n/**\n * A user-supplied object that describes a location. Used when providing\n * entries to `createMemoryHistory` via its `initialEntries` option.\n */\nexport type InitialEntry = string | Partial;\n\nexport type MemoryHistoryOptions = {\n initialEntries?: InitialEntry[];\n initialIndex?: number;\n v5Compat?: boolean;\n};\n\n/**\n * A memory history stores locations in memory. This is useful in stateful\n * environments where there is no web browser, such as node tests or React\n * Native.\n */\nexport interface MemoryHistory extends History {\n /**\n * The current index in the history stack.\n */\n readonly index: number;\n}\n\n/**\n * Memory history stores the current location in memory. It is designed for use\n * in stateful non-browser environments like tests and React Native.\n */\nexport function createMemoryHistory(\n options: MemoryHistoryOptions = {}\n): MemoryHistory {\n let { initialEntries = [\"/\"], initialIndex, v5Compat = false } = options;\n let entries: Location[]; // Declare so we can access from createMemoryLocation\n entries = initialEntries.map((entry, index) =>\n createMemoryLocation(\n entry,\n typeof entry === \"string\" ? null : entry.state,\n index === 0 ? \"default\" : undefined\n )\n );\n let index = clampIndex(\n initialIndex == null ? entries.length - 1 : initialIndex\n );\n let action = Action.Pop;\n let listener: Listener | null = null;\n\n function clampIndex(n: number): number {\n return Math.min(Math.max(n, 0), entries.length - 1);\n }\n function getCurrentLocation(): Location {\n return entries[index];\n }\n function createMemoryLocation(\n to: To,\n state: any = null,\n key?: string\n ): Location {\n let location = createLocation(\n entries ? getCurrentLocation().pathname : \"/\",\n to,\n state,\n key\n );\n warning(\n location.pathname.charAt(0) === \"/\",\n `relative pathnames are not supported in memory history: ${JSON.stringify(\n to\n )}`\n );\n return location;\n }\n\n function createHref(to: To) {\n return typeof to === \"string\" ? to : createPath(to);\n }\n\n let history: MemoryHistory = {\n get index() {\n return index;\n },\n get action() {\n return action;\n },\n get location() {\n return getCurrentLocation();\n },\n createHref,\n createURL(to) {\n return new URL(createHref(to), \"http://localhost\");\n },\n encodeLocation(to: To) {\n let path = typeof to === \"string\" ? parsePath(to) : to;\n return {\n pathname: path.pathname || \"\",\n search: path.search || \"\",\n hash: path.hash || \"\",\n };\n },\n push(to, state) {\n action = Action.Push;\n let nextLocation = createMemoryLocation(to, state);\n index += 1;\n entries.splice(index, entries.length, nextLocation);\n if (v5Compat && listener) {\n listener({ action, location: nextLocation, delta: 1 });\n }\n },\n replace(to, state) {\n action = Action.Replace;\n let nextLocation = createMemoryLocation(to, state);\n entries[index] = nextLocation;\n if (v5Compat && listener) {\n listener({ action, location: nextLocation, delta: 0 });\n }\n },\n go(delta) {\n action = Action.Pop;\n let nextIndex = clampIndex(index + delta);\n let nextLocation = entries[nextIndex];\n index = nextIndex;\n if (listener) {\n listener({ action, location: nextLocation, delta });\n }\n },\n listen(fn: Listener) {\n listener = fn;\n return () => {\n listener = null;\n };\n },\n };\n\n return history;\n}\n//#endregion\n\n////////////////////////////////////////////////////////////////////////////////\n//#region Browser History\n////////////////////////////////////////////////////////////////////////////////\n\n/**\n * A browser history stores the current location in regular URLs in a web\n * browser environment. This is the standard for most web apps and provides the\n * cleanest URLs the browser's address bar.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory\n */\nexport interface BrowserHistory extends UrlHistory {}\n\nexport type BrowserHistoryOptions = UrlHistoryOptions;\n\n/**\n * Browser history stores the location in regular URLs. This is the standard for\n * most web apps, but it requires some configuration on the server to ensure you\n * serve the same app at multiple URLs.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory\n */\nexport function createBrowserHistory(\n options: BrowserHistoryOptions = {}\n): BrowserHistory {\n function createBrowserLocation(\n window: Window,\n globalHistory: Window[\"history\"]\n ) {\n let { pathname, search, hash } = window.location;\n return createLocation(\n \"\",\n { pathname, search, hash },\n // state defaults to `null` because `window.history.state` does\n (globalHistory.state && globalHistory.state.usr) || null,\n (globalHistory.state && globalHistory.state.key) || \"default\"\n );\n }\n\n function createBrowserHref(window: Window, to: To) {\n return typeof to === \"string\" ? to : createPath(to);\n }\n\n return getUrlBasedHistory(\n createBrowserLocation,\n createBrowserHref,\n null,\n options\n );\n}\n//#endregion\n\n////////////////////////////////////////////////////////////////////////////////\n//#region Hash History\n////////////////////////////////////////////////////////////////////////////////\n\n/**\n * A hash history stores the current location in the fragment identifier portion\n * of the URL in a web browser environment.\n *\n * This is ideal for apps that do not control the server for some reason\n * (because the fragment identifier is never sent to the server), including some\n * shared hosting environments that do not provide fine-grained controls over\n * which pages are served at which URLs.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory\n */\nexport interface HashHistory extends UrlHistory {}\n\nexport type HashHistoryOptions = UrlHistoryOptions;\n\n/**\n * Hash history stores the location in window.location.hash. This makes it ideal\n * for situations where you don't want to send the location to the server for\n * some reason, either because you do cannot configure it or the URL space is\n * reserved for something else.\n *\n * @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory\n */\nexport function createHashHistory(\n options: HashHistoryOptions = {}\n): HashHistory {\n function createHashLocation(\n window: Window,\n globalHistory: Window[\"history\"]\n ) {\n let {\n pathname = \"/\",\n search = \"\",\n hash = \"\",\n } = parsePath(window.location.hash.substr(1));\n\n // Hash URL should always have a leading / just like window.location.pathname\n // does, so if an app ends up at a route like /#something then we add a\n // leading slash so all of our path-matching behaves the same as if it would\n // in a browser router. This is particularly important when there exists a\n // root splat route () since that matches internally against\n // \"/*\" and we'd expect /#something to 404 in a hash router app.\n if (!pathname.startsWith(\"/\") && !pathname.startsWith(\".\")) {\n pathname = \"/\" + pathname;\n }\n\n return createLocation(\n \"\",\n { pathname, search, hash },\n // state defaults to `null` because `window.history.state` does\n (globalHistory.state && globalHistory.state.usr) || null,\n (globalHistory.state && globalHistory.state.key) || \"default\"\n );\n }\n\n function createHashHref(window: Window, to: To) {\n let base = window.document.querySelector(\"base\");\n let href = \"\";\n\n if (base && base.getAttribute(\"href\")) {\n let url = window.location.href;\n let hashIndex = url.indexOf(\"#\");\n href = hashIndex === -1 ? url : url.slice(0, hashIndex);\n }\n\n return href + \"#\" + (typeof to === \"string\" ? to : createPath(to));\n }\n\n function validateHashLocation(location: Location, to: To) {\n warning(\n location.pathname.charAt(0) === \"/\",\n `relative pathnames are not supported in hash history.push(${JSON.stringify(\n to\n )})`\n );\n }\n\n return getUrlBasedHistory(\n createHashLocation,\n createHashHref,\n validateHashLocation,\n options\n );\n}\n//#endregion\n\n////////////////////////////////////////////////////////////////////////////////\n//#region UTILS\n////////////////////////////////////////////////////////////////////////////////\n\n/**\n * @private\n */\nexport function invariant(value: boolean, message?: string): asserts value;\nexport function invariant(\n value: T | null | undefined,\n message?: string\n): asserts value is T;\nexport function invariant(value: any, message?: string) {\n if (value === false || value === null || typeof value === \"undefined\") {\n throw new Error(message);\n }\n}\n\nexport function warning(cond: any, message: string) {\n if (!cond) {\n // eslint-disable-next-line no-console\n if (typeof console !== \"undefined\") console.warn(message);\n\n try {\n // Welcome to debugging history!\n //\n // This error is thrown as a convenience, so you can more easily\n // find the source for a warning that appears in the console by\n // enabling \"pause on exceptions\" in your JavaScript debugger.\n throw new Error(message);\n // eslint-disable-next-line no-empty\n } catch (e) {}\n }\n}\n\nfunction createKey() {\n return Math.random().toString(36).substr(2, 8);\n}\n\n/**\n * For browser-based histories, we combine the state and key into an object\n */\nfunction getHistoryState(location: Location, index: number): HistoryState {\n return {\n usr: location.state,\n key: location.key,\n idx: index,\n };\n}\n\n/**\n * Creates a Location object with a unique key from the given Path\n */\nexport function createLocation(\n current: string | Location,\n to: To,\n state: any = null,\n key?: string\n): Readonly {\n let location: Readonly = {\n pathname: typeof current === \"string\" ? current : current.pathname,\n search: \"\",\n hash: \"\",\n ...(typeof to === \"string\" ? parsePath(to) : to),\n state,\n // TODO: This could be cleaned up. push/replace should probably just take\n // full Locations now and avoid the need to run through this flow at all\n // But that's a pretty big refactor to the current test suite so going to\n // keep as is for the time being and just let any incoming keys take precedence\n key: (to && (to as Location).key) || key || createKey(),\n };\n return location;\n}\n\n/**\n * Creates a string URL path from the given pathname, search, and hash components.\n */\nexport function createPath({\n pathname = \"/\",\n search = \"\",\n hash = \"\",\n}: Partial) {\n if (search && search !== \"?\")\n pathname += search.charAt(0) === \"?\" ? search : \"?\" + search;\n if (hash && hash !== \"#\")\n pathname += hash.charAt(0) === \"#\" ? hash : \"#\" + hash;\n return pathname;\n}\n\n/**\n * Parses a string URL path into its separate pathname, search, and hash components.\n */\nexport function parsePath(path: string): Partial {\n let parsedPath: Partial = {};\n\n if (path) {\n let hashIndex = path.indexOf(\"#\");\n if (hashIndex >= 0) {\n parsedPath.hash = path.substr(hashIndex);\n path = path.substr(0, hashIndex);\n }\n\n let searchIndex = path.indexOf(\"?\");\n if (searchIndex >= 0) {\n parsedPath.search = path.substr(searchIndex);\n path = path.substr(0, searchIndex);\n }\n\n if (path) {\n parsedPath.pathname = path;\n }\n }\n\n return parsedPath;\n}\n\nexport interface UrlHistory extends History {}\n\nexport type UrlHistoryOptions = {\n window?: Window;\n v5Compat?: boolean;\n};\n\nfunction getUrlBasedHistory(\n getLocation: (window: Window, globalHistory: Window[\"history\"]) => Location,\n createHref: (window: Window, to: To) => string,\n validateLocation: ((location: Location, to: To) => void) | null,\n options: UrlHistoryOptions = {}\n): UrlHistory {\n let { window = document.defaultView!, v5Compat = false } = options;\n let globalHistory = window.history;\n let action = Action.Pop;\n let listener: Listener | null = null;\n\n let index = getIndex()!;\n // Index should only be null when we initialize. If not, it's because the\n // user called history.pushState or history.replaceState directly, in which\n // case we should log a warning as it will result in bugs.\n if (index == null) {\n index = 0;\n globalHistory.replaceState({ ...globalHistory.state, idx: index }, \"\");\n }\n\n function getIndex(): number {\n let state = globalHistory.state || { idx: null };\n return state.idx;\n }\n\n function handlePop() {\n action = Action.Pop;\n let nextIndex = getIndex();\n let delta = nextIndex == null ? null : nextIndex - index;\n index = nextIndex;\n if (listener) {\n listener({ action, location: history.location, delta });\n }\n }\n\n function push(to: To, state?: any) {\n action = Action.Push;\n let location = createLocation(history.location, to, state);\n if (validateLocation) validateLocation(location, to);\n\n index = getIndex() + 1;\n let historyState = getHistoryState(location, index);\n let url = history.createHref(location);\n\n // try...catch because iOS limits us to 100 pushState calls :/\n try {\n globalHistory.pushState(historyState, \"\", url);\n } catch (error) {\n // If the exception is because `state` can't be serialized, let that throw\n // outwards just like a replace call would so the dev knows the cause\n // https://html.spec.whatwg.org/multipage/nav-history-apis.html#shared-history-push/replace-state-steps\n // https://html.spec.whatwg.org/multipage/structured-data.html#structuredserializeinternal\n if (error instanceof DOMException && error.name === \"DataCloneError\") {\n throw error;\n }\n // They are going to lose state here, but there is no real\n // way to warn them about it since the page will refresh...\n window.location.assign(url);\n }\n\n if (v5Compat && listener) {\n listener({ action, location: history.location, delta: 1 });\n }\n }\n\n function replace(to: To, state?: any) {\n action = Action.Replace;\n let location = createLocation(history.location, to, state);\n if (validateLocation) validateLocation(location, to);\n\n index = getIndex();\n let historyState = getHistoryState(location, index);\n let url = history.createHref(location);\n globalHistory.replaceState(historyState, \"\", url);\n\n if (v5Compat && listener) {\n listener({ action, location: history.location, delta: 0 });\n }\n }\n\n function createURL(to: To): URL {\n // window.location.origin is \"null\" (the literal string value) in Firefox\n // under certain conditions, notably when serving from a local HTML file\n // See https://bugzilla.mozilla.org/show_bug.cgi?id=878297\n let base =\n window.location.origin !== \"null\"\n ? window.location.origin\n : window.location.href;\n\n let href = typeof to === \"string\" ? to : createPath(to);\n invariant(\n base,\n `No window.location.(origin|href) available to create URL for href: ${href}`\n );\n return new URL(href, base);\n }\n\n let history: History = {\n get action() {\n return action;\n },\n get location() {\n return getLocation(window, globalHistory);\n },\n listen(fn: Listener) {\n if (listener) {\n throw new Error(\"A history only accepts one active listener\");\n }\n window.addEventListener(PopStateEventType, handlePop);\n listener = fn;\n\n return () => {\n window.removeEventListener(PopStateEventType, handlePop);\n listener = null;\n };\n },\n createHref(to) {\n return createHref(window, to);\n },\n createURL,\n encodeLocation(to) {\n // Encode a Location the same way window.location would\n let url = createURL(to);\n return {\n pathname: url.pathname,\n search: url.search,\n hash: url.hash,\n };\n },\n push,\n replace,\n go(n) {\n return globalHistory.go(n);\n },\n };\n\n return history;\n}\n\n//#endregion\n","import type { Location, Path, To } from \"./history\";\nimport { invariant, parsePath, warning } from \"./history\";\n\n/**\n * Map of routeId -> data returned from a loader/action/error\n */\nexport interface RouteData {\n [routeId: string]: any;\n}\n\nexport enum ResultType {\n data = \"data\",\n deferred = \"deferred\",\n redirect = \"redirect\",\n error = \"error\",\n}\n\n/**\n * Successful result from a loader or action\n */\nexport interface SuccessResult {\n type: ResultType.data;\n data: any;\n statusCode?: number;\n headers?: Headers;\n}\n\n/**\n * Successful defer() result from a loader or action\n */\nexport interface DeferredResult {\n type: ResultType.deferred;\n deferredData: DeferredData;\n statusCode?: number;\n headers?: Headers;\n}\n\n/**\n * Redirect result from a loader or action\n */\nexport interface RedirectResult {\n type: ResultType.redirect;\n status: number;\n location: string;\n revalidate: boolean;\n reloadDocument?: boolean;\n}\n\n/**\n * Unsuccessful result from a loader or action\n */\nexport interface ErrorResult {\n type: ResultType.error;\n error: any;\n headers?: Headers;\n}\n\n/**\n * Result from a loader or action - potentially successful or unsuccessful\n */\nexport type DataResult =\n | SuccessResult\n | DeferredResult\n | RedirectResult\n | ErrorResult;\n\ntype LowerCaseFormMethod = \"get\" | \"post\" | \"put\" | \"patch\" | \"delete\";\ntype UpperCaseFormMethod = Uppercase;\n\n/**\n * Users can specify either lowercase or uppercase form methods on `