| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/shims/ |
Upload File : |
{"version":3,"file":"dynamic.js","names":[],"sources":["../../src/shims/dynamic.ts"],"sourcesContent":["/**\n * next/dynamic shim\n *\n * SSR-safe dynamic imports. On the server, uses React.lazy + Suspense so that\n * renderToReadableStream suspends until the dynamically-imported component is\n * available. On the client, also uses React.lazy for code splitting.\n *\n * Works in RSC, SSR, and client environments:\n * - RSC: Uses React.lazy + Suspense (available in React 19.x react-server).\n * Falls back to async component pattern if a future React version\n * strips lazy from react-server.\n * - SSR: React.lazy + Suspense (renderToReadableStream suspends)\n * - Client: React.lazy + Suspense (standard code splitting)\n *\n * Supports:\n * - dynamic(import('./Component'))\n * - dynamic(() => import('./Component'))\n * - dynamic({ loader })\n * - dynamic(() => import('./Component'), { loading: () => <Spinner /> })\n * - dynamic(() => import('./Component'), { ssr: false })\n */\nimport React, { type ComponentType } from \"react\";\n\ntype DynamicLoadingProps = {\n error?: Error | null;\n isLoading?: boolean;\n pastDelay?: boolean;\n retry?: () => void;\n timedOut?: boolean;\n};\n\ntype ComponentModule<P> = { default: ComponentType<P> };\ntype LoaderComponent<P> = Promise<ComponentModule<P> | ComponentType<P>>;\ntype LoaderFn<P> = () => LoaderComponent<P>;\n\ntype DynamicOptions<P> = {\n loading?: ComponentType<DynamicLoadingProps>;\n loader?: Loader<P>;\n ssr?: boolean;\n};\n\ntype Loader<P> = LoaderFn<P> | LoaderComponent<P>;\ntype DynamicInput<P> = DynamicOptions<P> | Loader<P>;\n\nconst noopRetry = () => {};\n\nfunction createDynamicLoadingProps(\n overrides: Partial<DynamicLoadingProps> = {},\n): DynamicLoadingProps {\n return {\n error: null,\n isLoading: true,\n pastDelay: true,\n retry: noopRetry,\n timedOut: false,\n ...overrides,\n };\n}\n\nfunction hasDefaultExport<P>(\n mod: ComponentModule<P> | ComponentType<P>,\n): mod is ComponentModule<P> {\n return (typeof mod === \"object\" || typeof mod === \"function\") && mod !== null && \"default\" in mod;\n}\n\nfunction normalizeLoader<P extends object>(loader: Loader<P>): LoaderFn<P> {\n if (typeof loader === \"function\") {\n return loader;\n }\n return () => loader;\n}\n\nfunction normalizeDynamicOptions<P extends object>(\n dynamicInput: DynamicInput<P>,\n options?: DynamicOptions<P>,\n): DynamicOptions<P> {\n let normalizedOptions: DynamicOptions<P>;\n\n if (dynamicInput instanceof Promise || typeof dynamicInput === \"function\") {\n normalizedOptions = { loader: normalizeLoader(dynamicInput) };\n } else {\n normalizedOptions = dynamicInput;\n }\n\n return {\n ...normalizedOptions,\n ...options,\n };\n}\n\nfunction createLazyComponent<P extends object>(loader: LoaderFn<P>) {\n return React.lazy(async () => {\n const mod = await loader();\n if (hasDefaultExport(mod)) return mod;\n return { default: mod };\n });\n}\n\nfunction useRetryableLazyComponent<P extends object>(\n loader: LoaderFn<P>,\n initialLazyComponent: ReturnType<typeof createLazyComponent<P>>,\n) {\n const [LazyComponent, setLazyComponent] = React.useState(() => initialLazyComponent);\n const [retryKey, setRetryKey] = React.useState(0);\n const retry = React.useCallback(() => {\n setLazyComponent(() => createLazyComponent(loader));\n setRetryKey((key) => key + 1);\n }, [loader]);\n return { LazyComponent, retry, retryKey };\n}\n\ntype DynamicErrorBoundaryProps = {\n fallback: ComponentType<DynamicLoadingProps>;\n retry: () => void;\n resetKey: number;\n children?: React.ReactNode;\n};\n\ntype DynamicErrorBoundaryState = {\n error: Error | null;\n resetKey: number;\n};\n\n/**\n * Lightweight error boundary that renders the loading component with the error\n * when a dynamic() loader rejects. Without this, loader failures would propagate\n * uncaught through React's rendering — this preserves the Next.js behavior where\n * the `loading` component can display errors.\n *\n * Lazily created because React.Component is not available in the RSC environment\n * (server components use a slimmed-down React that doesn't include class components).\n */\nlet DynamicErrorBoundary: ComponentType<DynamicErrorBoundaryProps> | null | undefined;\nfunction getDynamicErrorBoundary() {\n if (DynamicErrorBoundary) return DynamicErrorBoundary;\n if (!React.Component) return null;\n DynamicErrorBoundary = class extends (\n React.Component<DynamicErrorBoundaryProps, DynamicErrorBoundaryState>\n ) {\n constructor(props: DynamicErrorBoundaryProps) {\n super(props);\n this.state = { error: null, resetKey: props.resetKey };\n }\n static getDerivedStateFromProps(\n props: DynamicErrorBoundaryProps,\n state: DynamicErrorBoundaryState,\n ) {\n if (props.resetKey !== state.resetKey) {\n return { error: null, resetKey: props.resetKey };\n }\n return null;\n }\n static getDerivedStateFromError(error: unknown) {\n return { error: error instanceof Error ? error : new Error(String(error)) };\n }\n render() {\n if (this.state.error) {\n return React.createElement(\n this.props.fallback,\n createDynamicLoadingProps({\n isLoading: false,\n error: this.state.error,\n retry: this.props.retry,\n }),\n );\n }\n return this.props.children;\n }\n };\n return DynamicErrorBoundary;\n}\n\n// Detect server vs client\nconst isServer = typeof window === \"undefined\";\n\n// Legacy preload queue — kept for backward compatibility with Pages Router\n// which calls flushPreloads() before rendering. The App Router uses React.lazy\n// + Suspense instead, so this queue is no longer populated.\nconst preloadQueue: Promise<void>[] = [];\n\n/**\n * Wait for all pending dynamic() preloads to resolve, then clear the queue.\n * Called by the Pages Router SSR handler before rendering.\n * No-op for the App Router path which uses React.lazy + Suspense.\n */\nexport function flushPreloads(): Promise<void[]> {\n const pending = preloadQueue.splice(0);\n return Promise.all(pending);\n}\n\nfunction dynamic<P extends object = object>(\n dynamicInput: DynamicInput<P>,\n options?: DynamicOptions<P>,\n): ComponentType<P> {\n const {\n loader: dynamicLoader,\n loading: LoadingComponent,\n ssr = true,\n } = normalizeDynamicOptions(dynamicInput, options);\n const loader = dynamicLoader ? normalizeLoader(dynamicLoader) : () => Promise.resolve(() => null);\n\n // ssr: false — render nothing on the server, lazy-load on client\n if (!ssr) {\n if (isServer) {\n // On the server (SSR or RSC), just render the loading state or nothing\n const SSRFalse = (_props: P) =>\n LoadingComponent\n ? React.createElement(LoadingComponent, createDynamicLoadingProps({ pastDelay: false }))\n : null;\n SSRFalse.displayName = \"DynamicSSRFalse\";\n return SSRFalse;\n }\n\n const InitialLazyComponent = createLazyComponent(loader);\n\n const ClientSSRFalse = (props: P) => {\n const [mounted, setMounted] = React.useState(false);\n const { LazyComponent, retry, retryKey } = useRetryableLazyComponent(\n loader,\n InitialLazyComponent,\n );\n React.useEffect(() => setMounted(true), []);\n\n if (!mounted) {\n return LoadingComponent\n ? React.createElement(LoadingComponent, createDynamicLoadingProps({ retry }))\n : null;\n }\n\n const fallback = LoadingComponent\n ? React.createElement(LoadingComponent, createDynamicLoadingProps({ retry }))\n : null;\n const lazyElement = React.createElement(LazyComponent, props);\n let content: React.ReactNode = lazyElement;\n if (LoadingComponent) {\n const ErrorBoundary = getDynamicErrorBoundary();\n if (ErrorBoundary) {\n content = React.createElement(\n ErrorBoundary,\n { fallback: LoadingComponent, retry, resetKey: retryKey },\n lazyElement,\n );\n }\n }\n return React.createElement(React.Suspense, { fallback }, content);\n };\n\n ClientSSRFalse.displayName = \"DynamicClientSSRFalse\";\n return ClientSSRFalse;\n }\n\n // SSR-enabled path\n if (isServer) {\n // Defensive fallback: if a future React version strips React.lazy from the\n // react-server condition, fall back to an async component pattern.\n // In React 19.x, React.lazy IS available in react-server, so this branch\n // does not execute — it exists for forward compatibility only.\n if (typeof React.lazy !== \"function\") {\n const AsyncServerDynamic = async (props: P) => {\n // Note: LoadingComponent is not used here — in the RSC environment,\n // async components suspend natively and parent <Suspense> boundaries\n // provide loading states. Error handling also defers to the nearest\n // error boundary in the component tree.\n const mod = await loader();\n const Component =\n \"default\" in mod\n ? (mod as { default: ComponentType<P> }).default\n : (mod as ComponentType<P>);\n return React.createElement(Component, props);\n };\n AsyncServerDynamic.displayName = \"DynamicAsyncServer\";\n // Cast is safe: async components are natively supported by the RSC renderer,\n // but TypeScript's ComponentType<P> doesn't account for async return types.\n return AsyncServerDynamic as unknown as ComponentType<P>;\n }\n\n // SSR path: Use React.lazy so that renderToReadableStream can suspend\n // until the dynamically-imported component is available.\n const LazyServer = createLazyComponent(loader);\n\n const ServerDynamic = (props: P) => {\n const fallback = LoadingComponent\n ? React.createElement(LoadingComponent, createDynamicLoadingProps())\n : null;\n const lazyElement = React.createElement(LazyServer, props);\n // Wrap with error boundary so loader rejections render the loading\n // component with the error instead of propagating uncaught.\n let content: React.ReactNode = lazyElement;\n if (LoadingComponent) {\n const ErrorBoundary = getDynamicErrorBoundary();\n if (ErrorBoundary) {\n content = React.createElement(\n ErrorBoundary,\n { fallback: LoadingComponent, retry: noopRetry, resetKey: 0 },\n lazyElement,\n );\n }\n }\n return React.createElement(React.Suspense, { fallback }, content);\n };\n\n ServerDynamic.displayName = \"DynamicServer\";\n return ServerDynamic;\n }\n\n const InitialLazyComponent = createLazyComponent(loader);\n\n const ClientDynamic = (props: P) => {\n const { LazyComponent, retry, retryKey } = useRetryableLazyComponent(\n loader,\n InitialLazyComponent,\n );\n const fallback = LoadingComponent\n ? React.createElement(LoadingComponent, createDynamicLoadingProps({ retry }))\n : null;\n const lazyElement = React.createElement(LazyComponent, props);\n let content: React.ReactNode = lazyElement;\n if (LoadingComponent) {\n const ErrorBoundary = getDynamicErrorBoundary();\n if (ErrorBoundary) {\n content = React.createElement(\n ErrorBoundary,\n { fallback: LoadingComponent, retry, resetKey: retryKey },\n lazyElement,\n );\n }\n }\n return React.createElement(React.Suspense, { fallback }, content);\n };\n\n ClientDynamic.displayName = \"DynamicClient\";\n return ClientDynamic;\n}\n\nexport default dynamic;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAM,kBAAkB;AAExB,SAAS,0BACP,YAA0C,EAAE,EACvB;CACrB,OAAO;EACL,OAAO;EACP,WAAW;EACX,WAAW;EACX,OAAO;EACP,UAAU;EACV,GAA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