Skip to content

Commit fb78dd2

Browse files
authored
fix: invalidate models components cache based on location (#10764)
1 parent 8e1bfef commit fb78dd2

4 files changed

Lines changed: 46 additions & 6 deletions

File tree

src/core/plugins/oas31/wrap-components/model.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ const ModelWrapper = createOnlyOAS31ComponentWrapper(
1212
const { getComponent, fn, getConfigs } = system
1313
const configs = getConfigs()
1414

15+
const pathname = window?.location?.pathname ?? "/"
16+
17+
if (
18+
ModelWrapper.ModelWithJSONSchemaContext &&
19+
ModelWrapper.pathname === pathname
20+
) {
21+
return <ModelWrapper.ModelWithJSONSchemaContext {...props} />
22+
}
23+
1524
const Model = getComponent("OAS31Model")
1625
const withJSONSchemaSystemContext = getComponent(
1726
"withJSONSchema202012SystemContext"
1827
)
1928

2029
// we cache the HOC as recreating it with every re-render is quite expensive
21-
ModelWrapper.ModelWithJSONSchemaContext ??= withJSONSchemaSystemContext(
30+
ModelWrapper.ModelWithJSONSchemaContext = withJSONSchemaSystemContext(
2231
Model,
2332
{
2433
config: {
@@ -36,9 +45,13 @@ const ModelWrapper = createOnlyOAS31ComponentWrapper(
3645
},
3746
}
3847
)
48+
ModelWrapper.pathname = pathname
3949

4050
return <ModelWrapper.ModelWithJSONSchemaContext {...props} />
4151
}
4252
)
4353

54+
ModelWrapper.ModelWithJSONSchemaContext = null
55+
ModelWrapper.pathname = null
56+
4457
export default ModelWrapper

src/core/plugins/oas31/wrap-components/models.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
1010
const { getComponent, fn, getConfigs } = getSystem()
1111
const configs = getConfigs()
1212

13-
if (ModelsWrapper.ModelsWithJSONSchemaContext) {
13+
const pathname = window?.location?.pathname ?? "/"
14+
15+
if (
16+
ModelsWrapper.ModelsWithJSONSchemaContext &&
17+
ModelsWrapper.pathname === pathname
18+
) {
1419
return <ModelsWrapper.ModelsWithJSONSchemaContext />
1520
}
1621

@@ -20,7 +25,7 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
2025
)
2126

2227
// we cache the HOC as recreating it with every re-render is quite expensive
23-
ModelsWrapper.ModelsWithJSONSchemaContext ??= withJSONSchemaSystemContext(
28+
ModelsWrapper.ModelsWithJSONSchemaContext = withJSONSchemaSystemContext(
2429
Models,
2530
{
2631
config: {
@@ -38,10 +43,12 @@ const ModelsWrapper = createOnlyOAS31ComponentWrapper(({ getSystem }) => {
3843
},
3944
}
4045
)
46+
ModelsWrapper.pathname = pathname
4147

4248
return <ModelsWrapper.ModelsWithJSONSchemaContext />
4349
})
4450

4551
ModelsWrapper.ModelsWithJSONSchemaContext = null
52+
ModelsWrapper.pathname = null
4653

4754
export default ModelsWrapper

src/core/plugins/oas32/wrap-components/model.jsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ const ModelWrapper = createOnlyOAS32ComponentWrapper(
1212
const { getComponent, fn, getConfigs } = system
1313
const configs = getConfigs()
1414

15+
const pathname = window?.location?.pathname ?? "/"
16+
17+
if (
18+
ModelWrapper.ModelWithJSONSchemaContext &&
19+
ModelWrapper.pathname === pathname
20+
) {
21+
return <ModelWrapper.ModelWithJSONSchemaContext {...props} />
22+
}
23+
1524
const Model = getComponent("OAS31Model")
1625
const withJSONSchemaSystemContext = getComponent(
1726
"withJSONSchema202012SystemContext"
1827
)
1928

2029
// we cache the HOC as recreating it with every re-render is quite expensive
21-
ModelWrapper.ModelWithJSONSchemaContext ??= withJSONSchemaSystemContext(
30+
ModelWrapper.ModelWithJSONSchemaContext = withJSONSchemaSystemContext(
2231
Model,
2332
{
2433
config: {
@@ -36,9 +45,13 @@ const ModelWrapper = createOnlyOAS32ComponentWrapper(
3645
},
3746
}
3847
)
48+
ModelWrapper.pathname = pathname
3949

4050
return <ModelWrapper.ModelWithJSONSchemaContext {...props} />
4151
}
4252
)
4353

54+
ModelWrapper.ModelWithJSONSchemaContext = null
55+
ModelWrapper.pathname = null
56+
4457
export default ModelWrapper

src/core/plugins/oas32/wrap-components/models.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const ModelsWrapper = createOnlyOAS32ComponentWrapper(({ getSystem }) => {
1010
const { getComponent, fn, getConfigs } = getSystem()
1111
const configs = getConfigs()
1212

13-
if (ModelsWrapper.ModelsWithJSONSchemaContext) {
13+
const pathname = window?.location?.pathname ?? "/"
14+
15+
if (
16+
ModelsWrapper.ModelsWithJSONSchemaContext &&
17+
ModelsWrapper.pathname === pathname
18+
) {
1419
return <ModelsWrapper.ModelsWithJSONSchemaContext />
1520
}
1621

@@ -20,7 +25,7 @@ const ModelsWrapper = createOnlyOAS32ComponentWrapper(({ getSystem }) => {
2025
)
2126

2227
// we cache the HOC as recreating it with every re-render is quite expensive
23-
ModelsWrapper.ModelsWithJSONSchemaContext ??= withJSONSchemaSystemContext(
28+
ModelsWrapper.ModelsWithJSONSchemaContext = withJSONSchemaSystemContext(
2429
Models,
2530
{
2631
config: {
@@ -38,10 +43,12 @@ const ModelsWrapper = createOnlyOAS32ComponentWrapper(({ getSystem }) => {
3843
},
3944
}
4045
)
46+
ModelsWrapper.pathname = pathname
4147

4248
return <ModelsWrapper.ModelsWithJSONSchemaContext />
4349
})
4450

4551
ModelsWrapper.ModelsWithJSONSchemaContext = null
52+
ModelsWrapper.pathname = null
4653

4754
export default ModelsWrapper

0 commit comments

Comments
 (0)