diff --git a/src/core/plugins/oas31/wrap-components/model.jsx b/src/core/plugins/oas31/wrap-components/model.jsx index 52b4ba99436..3a7e30ae77d 100644 --- a/src/core/plugins/oas31/wrap-components/model.jsx +++ b/src/core/plugins/oas31/wrap-components/model.jsx @@ -12,13 +12,22 @@ const ModelWrapper = createOnlyOAS31ComponentWrapper( const { getComponent, fn, getConfigs } = system const configs = getConfigs() + const pathname = window?.location?.pathname ?? "/" + + if ( + ModelWrapper.ModelWithJSONSchemaContext && + ModelWrapper.pathname === pathname + ) { + return + } + const Model = getComponent("OAS31Model") const withJSONSchemaSystemContext = getComponent( "withJSONSchema202012SystemContext" ) // we cache the HOC as recreating it with every re-render is quite expensive - ModelWrapper.ModelWithJSONSchemaContext ??= withJSONSchemaSystemContext( + ModelWrapper.ModelWithJSONSchemaContext = withJSONSchemaSystemContext( Model, { config: { @@ -36,9 +45,13 @@ const ModelWrapper = createOnlyOAS31ComponentWrapper( }, } ) + ModelWrapper.pathname = pathname return } ) +ModelWrapper.ModelWithJSONSchemaContext = null +ModelWrapper.pathname = null + export default ModelWrapper diff --git a/src/core/plugins/oas31/wrap-components/models.jsx b/src/core/plugins/oas31/wrap-components/models.jsx index 789a44f16cc..0c1fd763885 100644 --- a/src/core/plugins/oas31/wrap-components/models.jsx +++ b/src/core/plugins/oas31/wrap-components/models.jsx @@ -10,7 +10,12 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { const { getComponent, fn, getConfigs } = getSystem() const configs = getConfigs() - if (ModelsWrapper.ModelsWithJSONSchemaContext) { + const pathname = window?.location?.pathname ?? "/" + + if ( + ModelsWrapper.ModelsWithJSONSchemaContext && + ModelsWrapper.pathname === pathname + ) { return } @@ -20,7 +25,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { ) // we cache the HOC as recreating it with every re-render is quite expensive - ModelsWrapper.ModelsWithJSONSchemaContext ??= withJSONSchemaSystemContext( + ModelsWrapper.ModelsWithJSONSchemaContext = withJSONSchemaSystemContext( Models, { config: { @@ -38,10 +43,12 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => { }, } ) + ModelsWrapper.pathname = pathname return }) ModelsWrapper.ModelsWithJSONSchemaContext = null +ModelsWrapper.pathname = null export default ModelsWrapper diff --git a/src/core/plugins/oas32/wrap-components/model.jsx b/src/core/plugins/oas32/wrap-components/model.jsx index c4ca0416ec6..455ed94fea4 100644 --- a/src/core/plugins/oas32/wrap-components/model.jsx +++ b/src/core/plugins/oas32/wrap-components/model.jsx @@ -12,13 +12,22 @@ const ModelWrapper = createOnlyOAS32ComponentWrapper( const { getComponent, fn, getConfigs } = system const configs = getConfigs() + const pathname = window?.location?.pathname ?? "/" + + if ( + ModelWrapper.ModelWithJSONSchemaContext && + ModelWrapper.pathname === pathname + ) { + return + } + const Model = getComponent("OAS31Model") const withJSONSchemaSystemContext = getComponent( "withJSONSchema202012SystemContext" ) // we cache the HOC as recreating it with every re-render is quite expensive - ModelWrapper.ModelWithJSONSchemaContext ??= withJSONSchemaSystemContext( + ModelWrapper.ModelWithJSONSchemaContext = withJSONSchemaSystemContext( Model, { config: { @@ -36,9 +45,13 @@ const ModelWrapper = createOnlyOAS32ComponentWrapper( }, } ) + ModelWrapper.pathname = pathname return } ) +ModelWrapper.ModelWithJSONSchemaContext = null +ModelWrapper.pathname = null + export default ModelWrapper diff --git a/src/core/plugins/oas32/wrap-components/models.jsx b/src/core/plugins/oas32/wrap-components/models.jsx index 1a364c76eec..de4c997e16b 100644 --- a/src/core/plugins/oas32/wrap-components/models.jsx +++ b/src/core/plugins/oas32/wrap-components/models.jsx @@ -10,7 +10,12 @@ const ModelsWrapper = createOnlyOAS32ComponentWrapper(({ getSystem }) => { const { getComponent, fn, getConfigs } = getSystem() const configs = getConfigs() - if (ModelsWrapper.ModelsWithJSONSchemaContext) { + const pathname = window?.location?.pathname ?? "/" + + if ( + ModelsWrapper.ModelsWithJSONSchemaContext && + ModelsWrapper.pathname === pathname + ) { return } @@ -20,7 +25,7 @@ const ModelsWrapper = createOnlyOAS32ComponentWrapper(({ getSystem }) => { ) // we cache the HOC as recreating it with every re-render is quite expensive - ModelsWrapper.ModelsWithJSONSchemaContext ??= withJSONSchemaSystemContext( + ModelsWrapper.ModelsWithJSONSchemaContext = withJSONSchemaSystemContext( Models, { config: { @@ -38,10 +43,12 @@ const ModelsWrapper = createOnlyOAS32ComponentWrapper(({ getSystem }) => { }, } ) + ModelsWrapper.pathname = pathname return }) ModelsWrapper.ModelsWithJSONSchemaContext = null +ModelsWrapper.pathname = null export default ModelsWrapper