/* Copyright 2026 Marimo. All rights reserved. */ import React from "react"; interface LazyComponentWithPreload { preload: () => void; Component: React.LazyExoticComponent>; } export const reactLazyWithPreload = ( factory: () => Promise<{ default: React.ComponentType }>, ): LazyComponentWithPreload => { let component: Promise<{ default: React.ComponentType }> | null = null; const preload = async () => { if (!component) { component = factory(); } return component; }; const LazyComponent = React.lazy(() => { return preload(); }); return { preload, Component: LazyComponent, }; };