mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
React 19 modernization: forwardRef removal, Compiler, ErrorBoundary, Suspense, native <script>
Adopt React 19 idioms across the codebase. The runtime was already on
react@19.2.5 but no React 19 APIs were in use.
- forwardRef -> ref-as-prop in 7 layout/component files
(NitroInput/Button/ItemCountBadge/Card×5/InfiniteGridItem,
ToolbarItemView, AvatarEditorIcon)
- <Ctx.Provider> -> <Ctx> in 6 contexts (CatalogAdmin, FloorplanEditor,
UiSettings, GridContext, NitroCardContext, NitroCardAccordionContext)
- Native <script> hoisting for Turnstile, ExternalPluginLoader, GoogleAdsView
(React 19 dedupes by src; removes manual document.head.appendChild +
module-level promise caches)
- React Compiler enabled at build time via babel-plugin-react-compiler
in vite.config.mjs (target: '19'), plus eslint-plugin-react-compiler
in lint mode
- Global <ErrorBoundary> + <Suspense> in src/index.tsx using
react-error-boundary, with LoadingView as fallback
- BackgroundsView migrated to use(promise) as a demonstrator pattern
for Suspense-driven config loading
- ESLint react setting bumped 18.3.1 -> 19.2; legacy
@typescript-eslint/ban-types replaced with no-restricted-types
(the old rule was removed in @typescript-eslint v8)
- Refresh public/configuration/{asset-loader,bootstrap}.js to match
current write-asset-loader.mjs output
Phase 3 (login forms -> useActionState/useFormStatus) deferred:
LoginView is 1623 lines with lockout + Turnstile + heartbeat
interleaving; safer as its own PR.
https://claude.ai/code/session_01GrR87LAqnAEyKG2ZbmQt5Q
This commit is contained in:
@@ -2,29 +2,25 @@ import { FC, useEffect, useState } from 'react';
|
||||
import { GetConfigurationValue } from '../../api';
|
||||
import { subscribePlugins } from './NitroPluginApi';
|
||||
|
||||
// Force the global API to be initialized
|
||||
import './NitroPluginApi';
|
||||
|
||||
export const ExternalPluginLoader: FC<{}> = () =>
|
||||
{
|
||||
const [, forceUpdate] = useState(0);
|
||||
const [ pluginUrls, setPluginUrls ] = useState<string[]>([]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
return subscribePlugins(() => forceUpdate(n => n + 1));
|
||||
}, []);
|
||||
|
||||
// MainView only renders after isReady=true in App.tsx,
|
||||
// so the configuration is guaranteed to be loaded at this point.
|
||||
useEffect(() =>
|
||||
{
|
||||
const scripts: HTMLScriptElement[] = [];
|
||||
|
||||
let pluginUrls: string[] = [];
|
||||
let urls: string[] = [];
|
||||
|
||||
try
|
||||
{
|
||||
pluginUrls = GetConfigurationValue<string[]>('external.plugins', []);
|
||||
urls = GetConfigurationValue<string[]>('external.plugins', []) || [];
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
@@ -32,30 +28,28 @@ export const ExternalPluginLoader: FC<{}> = () =>
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pluginUrls || pluginUrls.length === 0)
|
||||
if (!urls.length)
|
||||
{
|
||||
console.log('[NitroPlugins] No external plugins configured');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[NitroPlugins] Loading external plugins:', pluginUrls);
|
||||
|
||||
for (const url of pluginUrls)
|
||||
{
|
||||
const script = document.createElement('script');
|
||||
script.src = url;
|
||||
script.async = true;
|
||||
script.onload = () => console.log(`[NitroPlugins] Loaded: ${url}`);
|
||||
script.onerror = () => console.warn(`[NitroPlugins] Failed to load: ${url}`);
|
||||
document.head.appendChild(script);
|
||||
scripts.push(script);
|
||||
}
|
||||
|
||||
return () =>
|
||||
{
|
||||
scripts.forEach(s => s.remove());
|
||||
};
|
||||
console.log('[NitroPlugins] Loading external plugins:', urls);
|
||||
setPluginUrls(urls);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
if (!pluginUrls.length) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
{ pluginUrls.map(url => (
|
||||
<script
|
||||
key={ url }
|
||||
async
|
||||
src={ url }
|
||||
onLoad={ () => console.log(`[NitroPlugins] Loaded: ${ url }`) }
|
||||
onError={ () => console.warn(`[NitroPlugins] Failed to load: ${ url }`) } />
|
||||
)) }
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user