From 694d3801fefc23d223fd404390d51f6403a5775b Mon Sep 17 00:00:00 2001 From: Nicolas Brichet <32258950+brichet@users.noreply.github.com> Date: Tue, 5 Sep 2023 14:57:08 +0200 Subject: [PATCH] Remove the loop to discover transform function if not registered (#14990) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove the loop to discover transform function if not registered * Update packages/settingregistry/src/settingregistry.ts Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com> * Update packages/settingregistry/src/settingregistry.ts Co-authored-by: Afshin Taylor Darian * Syntax --------- Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com> Co-authored-by: Afshin Taylor Darian --- .../settingregistry/src/settingregistry.ts | 35 ++++--------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/packages/settingregistry/src/settingregistry.ts b/packages/settingregistry/src/settingregistry.ts index c1e71224ff6a..02b6edd701d9 100644 --- a/packages/settingregistry/src/settingregistry.ts +++ b/packages/settingregistry/src/settingregistry.ts @@ -38,13 +38,6 @@ const AJV_DEFAULT_OPTIONS: Partial = { strict: false }; -/** - * The default number of milliseconds before a `load()` call to the registry - * will wait before timing out if it requires a transformation that has not been - * registered. - */ -const DEFAULT_TRANSFORM_TIMEOUT = 1000; - /** * The ASCII record separator character. */ @@ -280,7 +273,6 @@ export class SettingRegistry implements ISettingRegistry { constructor(options: SettingRegistry.IOptions) { this.connector = options.connector; this.validator = options.validator || new DefaultSchemaValidator(); - this._timeout = options.timeout || DEFAULT_TRANSFORM_TIMEOUT; // Plugins with transformation may not be loaded if the transformation function is // not yet available. To avoid fetching again the associated data when the transformation @@ -605,8 +597,8 @@ export class SettingRegistry implements ISettingRegistry { // Apply a transformation to the plugin if necessary. await this._load(await this._transform('fetch', plugin)); } catch (errors) { - /* Ignore preload timeout errors silently. */ - if (errors[0]?.keyword !== 'timeout') { + /* Ignore silently if no transformers. */ + if (errors[0]?.keyword !== 'unset') { console.warn('Ignored setting registry preload errors.', errors); } } @@ -653,13 +645,10 @@ export class SettingRegistry implements ISettingRegistry { */ private async _transform( phase: ISettingRegistry.IPlugin.Phase, - plugin: ISettingRegistry.IPlugin, - started = new Date().getTime() + plugin: ISettingRegistry.IPlugin ): Promise { - const elapsed = new Date().getTime() - started; const id = plugin.id; const transformers = this._transformers; - const timeout = this._timeout; if (!plugin.schema['jupyter.lab.transform']) { return plugin; @@ -678,25 +667,14 @@ export class SettingRegistry implements ISettingRegistry { } as ISchemaValidator.IError ]; } - return transformed; } - - // If the timeout has not been exceeded, stall and try again in 250ms. - if (elapsed < timeout) { - await new Promise(resolve => { - setTimeout(() => { - resolve(); - }, 250); - }); - return this._transform(phase, plugin, started); - } - + // If the plugin has no transformers, throw an error and bail. throw [ { instancePath: '', - keyword: 'timeout', - message: `Transforming ${plugin.id} timed out.`, + keyword: 'unset', + message: `${plugin.id} has no transformers yet.`, schemaPath: '' } as ISchemaValidator.IError ]; @@ -719,7 +697,6 @@ export class SettingRegistry implements ISettingRegistry { private _pluginChanged = new Signal(this); private _ready = Promise.resolve(); - private _timeout: number; private _transformers: { [plugin: string]: { [phase in ISettingRegistry.IPlugin.Phase]: ISettingRegistry.IPlugin.Transform;