From 9249dcb896b97ef8f83f1e07daed9b2eec69be55 Mon Sep 17 00:00:00 2001 From: jack zhang <1098626505@qq.com> Date: Sun, 5 Nov 2023 19:22:41 +0800 Subject: [PATCH] fix: application bug (#2958) * fix: application bug --- packages/core/app/client/src/pages/index.tsx | 1 + packages/core/client/src/application/Application.tsx | 3 ++- packages/core/client/src/application/PluginManager.ts | 5 ++++- .../src/application/__tests__/Application.test.tsx | 9 ++++----- .../client/src/application/components/AppComponent.tsx | 2 +- packages/core/client/src/application/utils/index.tsx | 2 +- .../schema-component/core/SchemaComponentProvider.tsx | 1 + 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/core/app/client/src/pages/index.tsx b/packages/core/app/client/src/pages/index.tsx index 4381b7fe80..82c94739e1 100644 --- a/packages/core/app/client/src/pages/index.tsx +++ b/packages/core/app/client/src/pages/index.tsx @@ -8,6 +8,7 @@ export const app = new Application({ }, plugins: [NocoBaseClientPresetPlugin], ws: true, + loadRemotePlugins: true, devDynamicImport, }); diff --git a/packages/core/client/src/application/Application.tsx b/packages/core/client/src/application/Application.tsx index c213ecbe3d..95b0d7ee38 100644 --- a/packages/core/client/src/application/Application.tsx +++ b/packages/core/client/src/application/Application.tsx @@ -38,6 +38,7 @@ export interface ApplicationOptions { scopes?: Record; router?: RouterOptions; devDynamicImport?: DevDynamicImport; + loadRemotePlugins?: boolean; } export class Application { @@ -75,7 +76,7 @@ export class Application { ...options.router, renderComponent: this.renderComponent.bind(this), }); - this.pm = new PluginManager(options.plugins, this); + this.pm = new PluginManager(options.plugins, options.loadRemotePlugins, this); this.addDefaultProviders(); this.addReactRouterComponents(); this.addProviders(options.providers || []); diff --git a/packages/core/client/src/application/PluginManager.ts b/packages/core/client/src/application/PluginManager.ts index b753281488..740713f911 100644 --- a/packages/core/client/src/application/PluginManager.ts +++ b/packages/core/client/src/application/PluginManager.ts @@ -19,6 +19,7 @@ export class PluginManager { constructor( protected _plugins: PluginType[], + protected loadRemotePlugins: boolean, protected app: Application, ) { this.app = app; @@ -27,7 +28,9 @@ export class PluginManager { async init(_plugins: PluginType[]) { await this.initStaticPlugins(_plugins); - await this.initRemotePlugins(); + if (this.loadRemotePlugins) { + await this.initRemotePlugins(); + } } private async initStaticPlugins(_plugins: PluginType[] = []) { diff --git a/packages/core/client/src/application/__tests__/Application.test.tsx b/packages/core/client/src/application/__tests__/Application.test.tsx index 5b87ddbaac..ef34fec7bf 100644 --- a/packages/core/client/src/application/__tests__/Application.test.tsx +++ b/packages/core/client/src/application/__tests__/Application.test.tsx @@ -331,8 +331,8 @@ describe('Application', () => { router, }); - const ErrorFallback = () => { - return
ErrorFallback
; + const AppError = () => { + return
AppError
; }; const Foo = () => { throw new Error('error'); @@ -340,7 +340,7 @@ describe('Application', () => { }; app.use(Foo); app.addComponents({ - ErrorFallback, + AppError, }); const originalConsoleWarn = console.error; @@ -352,8 +352,7 @@ describe('Application', () => { await sleep(10); expect(fn).toBeCalled(); - expect(screen.getByText('ErrorFallback')).toBeInTheDocument(); - screen.debug(); + expect(screen.getByText('AppError')).toBeInTheDocument(); console.error = originalConsoleWarn; }); diff --git a/packages/core/client/src/application/components/AppComponent.tsx b/packages/core/client/src/application/components/AppComponent.tsx index 9b596038ca..49d730a918 100644 --- a/packages/core/client/src/application/components/AppComponent.tsx +++ b/packages/core/client/src/application/components/AppComponent.tsx @@ -23,7 +23,7 @@ export const AppComponent: FC = observer((props) => { if (app.error?.code === 'LOAD_ERROR') return app.renderComponent('AppError', { app }); return ( - ('ErrorFallback')} onError={handleErrors}> + ('AppError')} onError={handleErrors}> {app.maintained && app.maintaining && app.renderComponent('AppMaintainingDialog', { app })} {app.renderComponent('AppMain')} diff --git a/packages/core/client/src/application/utils/index.tsx b/packages/core/client/src/application/utils/index.tsx index 0f3e916cb3..8a69d82723 100644 --- a/packages/core/client/src/application/utils/index.tsx +++ b/packages/core/client/src/application/utils/index.tsx @@ -28,7 +28,7 @@ export const compose = (...components: [ComponentType, any][]) => { {children} ); - ComposeComponent.displayName = Child.displayName; + ComposeComponent.displayName = Child.displayName || Child.name; return ComposeComponent; }, BlankComponent); diff --git a/packages/core/client/src/schema-component/core/SchemaComponentProvider.tsx b/packages/core/client/src/schema-component/core/SchemaComponentProvider.tsx index fba98a941c..83fa94139b 100644 --- a/packages/core/client/src/schema-component/core/SchemaComponentProvider.tsx +++ b/packages/core/client/src/schema-component/core/SchemaComponentProvider.tsx @@ -74,3 +74,4 @@ export const SchemaComponentProvider: React.FC = (prop ); }; +SchemaComponentProvider.displayName = 'SchemaComponentProvider';