import { Suspense, StrictMode } from 'react'; import { createRoot, render } from '@wordpress/element'; import { QueryClient, QueryCache, QueryClientProvider } from '@tanstack/react-query'; import { RouterProvider, createRouter, createBrowserHistory, createHashHistory } from '@tanstack/react-router'; // StyleSheetManager is used to configure styled-components globally // We need this to filter out the 'right' prop that react-data-table-component // passes to styled components, which causes warnings in styled-components v6 import { StyleSheetManager } from 'styled-components'; import isPropValid from '@emotion/is-prop-valid'; import { ThemeProvider } from './hooks/useTheme'; // Import the generated route tree import { routeTree } from './routeTree.gen'; const shouldForwardProp = ( prop: string ) => { // List of react-data-table-component specific props that should not be forwarded to DOM const dataTableProps = [ 'right', 'grow', 'wrap', 'allowOverflow', 'button', 'center', 'compact', 'hide', 'ignoreRowClick', 'maxWidth', 'minWidth', 'omit', 'reorder', 'sortable', 'width' ]; // Filter out data table props first if ( dataTableProps.includes( prop ) ) { return false; } // Then use isPropValid for standard HTML validation return isPropValid( prop ); }; export type { BurstMenuPro, BurstMenuGroup, BurstMenuItem, BurstMenuPage, BurstMenuConfig, BurstSettings } from './types/burst-settings'; declare global { interface Window { burstLoaded?: boolean; } } // This bundle is mounted in wp-admin and on shared dashboard URLs. wp-admin // still needs hash routing, while /burst-dashboard// should behave like a // normal path-based app. const isSharedDashboardRoute = /\/burst-dashboard(\/|$)/.test( window.location.pathname ); const routerHistory = isSharedDashboardRoute ? createBrowserHistory() : createHashHistory(); const HOUR_IN_SECONDS = 3600; interface QueryConfig { defaultOptions: { queries: { staleTime: number; refetchOnWindowFocus: boolean; retry: boolean; suspense: boolean; }; }; queryCache?: QueryCache; } const queryCache = new QueryCache(); let config: QueryConfig = { defaultOptions: { queries: { staleTime: HOUR_IN_SECONDS * 1000, // hour in ms refetchOnWindowFocus: false, retry: false, suspense: false // Disable Suspense for React Query, as it leads to loading the proper layout earlier. } } }; // merge queryCache with config config = { ...config, ...{ queryCache } }; const queryClient = new QueryClient( config ); const isPro = window.burst_settings?.is_pro; const canViewSales = window.burst_settings?.view_sales_burst_statistics; const menus = window.burst_settings?.menu; const normalizedMenus = Array.isArray( menus ) ? menus : Object.values( menus ?? {}); if ( window.burst_settings ) { // Normalize menu here itself. window.burst_settings.menu = normalizedMenus; } // Create the router with improved loading state const router = createRouter({ routeTree, context: { queryClient, isPro, canViewSales, menus: normalizedMenus }, defaultPendingComponent: () => , defaultErrorComponent: ({ error }) => (

Error

{error?.message || 'An unexpected error occurred'}

), history: routerHistory, // Shared links are mounted under /burst-dashboard, but the route tree itself // still uses app-relative paths such as /statistics and /story. ...( isSharedDashboardRoute ? { basepath: '/burst-dashboard' } : {}), defaultPreload: 'viewport' // Since we're using React Query, we don't want loader calls to ever be stale // This will ensure that the loader is always called when the route is preloaded or visited // defaultPreloadStaleTime: 0, }); const PendingComponent = () => { return ( <> {/* Left Block */}
{/* Middle Block */}
{/* Right Block */}
); }; const AppShell = () => { return ( }>