fix: application bug (#2958)

* fix: application bug
This commit is contained in:
jack zhang 2023-11-05 19:22:41 +08:00 committed by GitHub
parent bce02ad1d7
commit 9249dcb896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 9 deletions

View File

@ -8,6 +8,7 @@ export const app = new Application({
},
plugins: [NocoBaseClientPresetPlugin],
ws: true,
loadRemotePlugins: true,
devDynamicImport,
});

View File

@ -38,6 +38,7 @@ export interface ApplicationOptions {
scopes?: Record<string, any>;
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 || []);

View File

@ -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[] = []) {

View File

@ -331,8 +331,8 @@ describe('Application', () => {
router,
});
const ErrorFallback = () => {
return <div>ErrorFallback</div>;
const AppError = () => {
return <div>AppError</div>;
};
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;
});

View File

@ -23,7 +23,7 @@ export const AppComponent: FC<AppComponentProps> = observer((props) => {
if (app.error?.code === 'LOAD_ERROR') return app.renderComponent('AppError', { app });
return (
<ErrorBoundary FallbackComponent={app.getComponent<FallbackProps>('ErrorFallback')} onError={handleErrors}>
<ErrorBoundary FallbackComponent={app.getComponent<FallbackProps>('AppError')} onError={handleErrors}>
<ApplicationContext.Provider value={app}>
{app.maintained && app.maintaining && app.renderComponent('AppMaintainingDialog', { app })}
{app.renderComponent('AppMain')}

View File

@ -28,7 +28,7 @@ export const compose = (...components: [ComponentType, any][]) => {
<Child {...childProps}>{children}</Child>
</Parent>
);
ComposeComponent.displayName = Child.displayName;
ComposeComponent.displayName = Child.displayName || Child.name;
return ComposeComponent;
}, BlankComponent);

View File

@ -74,3 +74,4 @@ export const SchemaComponentProvider: React.FC<ISchemaComponentProvider> = (prop
</SchemaComponentContext.Provider>
);
};
SchemaComponentProvider.displayName = 'SchemaComponentProvider';