Files
vercel_dashboard_example/.pnpm-store/v11/files/2d/f3be3b9a283c0426706fe240af93d7ce3dbf8dd3fc543300df4a7877042654c6f02336890f4fd4283380a859fc77039f3fd2a2cc31aa2c6bc5db13ae111e5d
T
2026-05-12 14:53:15 +00:00

78 lines
2.5 KiB
Plaintext

'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import React, { useEffect } from 'react';
import { useRouter } from './navigation';
import { getRedirectTypeFromError, getURLFromRedirectError } from './redirect';
import { RedirectType, isRedirectError } from './redirect-error';
function HandleRedirect({ redirect, reset, redirectType }) {
const router = useRouter();
useEffect(()=>{
React.startTransition(()=>{
if (redirectType === RedirectType.push) {
router.push(redirect, {});
} else {
router.replace(redirect, {});
}
reset();
});
}, [
redirect,
redirectType,
reset,
router
]);
return null;
}
export class RedirectErrorBoundary extends React.Component {
constructor(props){
super(props);
this.state = {
redirect: null,
redirectType: null
};
}
static getDerivedStateFromError(error) {
if (isRedirectError(error)) {
const url = getURLFromRedirectError(error);
const redirectType = getRedirectTypeFromError(error);
if ('handled' in error) {
// The redirect was already handled. We'll still catch the redirect error
// so that we can remount the subtree, but we don't actually need to trigger the
// router.push.
return {
redirect: null,
redirectType: null
};
}
return {
redirect: url,
redirectType
};
}
// Re-throw if error is not for redirect
throw error;
}
// Explicit type is needed to avoid the generated `.d.ts` having a wide return type that could be specific to the `@types/react` version.
render() {
const { redirect, redirectType } = this.state;
if (redirect !== null && redirectType !== null) {
return /*#__PURE__*/ _jsx(HandleRedirect, {
redirect: redirect,
redirectType: redirectType,
reset: ()=>this.setState({
redirect: null
})
});
}
return this.props.children;
}
}
export function RedirectBoundary({ children }) {
const router = useRouter();
return /*#__PURE__*/ _jsx(RedirectErrorBoundary, {
router: router,
children: children
});
}
//# sourceMappingURL=redirect-boundary.js.map