@backstage/core-plugin-api 1.12.9-next.0 → 1.12.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @backstage/core-plugin-api
|
|
2
2
|
|
|
3
|
+
## 1.12.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9fcfbc9: Fixed a performance issue where all components using analytics, including every link, would rerender unnecessarily whenever a surrounding analytics context rendered again without its attributes having changed, for example when a URL query parameter changed on an entity page.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/frontend-plugin-api@0.18.0
|
|
10
|
+
|
|
11
|
+
## 1.12.9-next.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 9fcfbc9: Fixed a performance issue where all components using analytics, including every link, would rerender unnecessarily whenever a surrounding analytics context rendered again without its attributes having changed, for example when a URL query parameter changed on an entity page.
|
|
16
|
+
|
|
3
17
|
## 1.12.9-next.0
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { createVersionedContext, createVersionedValueMap } from '@backstage/version-bridge';
|
|
3
|
-
import { useContext } from 'react';
|
|
3
|
+
import { useMemo, useContext } from 'react';
|
|
4
4
|
|
|
5
5
|
const AnalyticsReactContext = createVersionedContext("analytics-context");
|
|
6
|
+
const defaultAnalyticsContext = Object.freeze({
|
|
7
|
+
routeRef: "unknown",
|
|
8
|
+
pluginId: "root",
|
|
9
|
+
extension: "App"
|
|
10
|
+
});
|
|
6
11
|
const useAnalyticsContext = () => {
|
|
7
12
|
const theContext = useContext(AnalyticsReactContext);
|
|
8
13
|
if (theContext === void 0) {
|
|
9
|
-
return
|
|
10
|
-
routeRef: "unknown",
|
|
11
|
-
pluginId: "root",
|
|
12
|
-
extension: "App"
|
|
13
|
-
};
|
|
14
|
+
return defaultAnalyticsContext;
|
|
14
15
|
}
|
|
15
16
|
const theValue = theContext.atVersion(1);
|
|
16
17
|
if (theValue === void 0) {
|
|
@@ -21,11 +22,10 @@ const useAnalyticsContext = () => {
|
|
|
21
22
|
const AnalyticsContext = (options) => {
|
|
22
23
|
const { attributes, children } = options;
|
|
23
24
|
const parentValues = useAnalyticsContext();
|
|
24
|
-
const
|
|
25
|
-
...parentValues,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const versionedCombinedValue = createVersionedValueMap({ 1: combinedValue });
|
|
25
|
+
const versionedCombinedValue = useMemo(
|
|
26
|
+
() => createVersionedValueMap({ 1: { ...parentValues, ...attributes } }),
|
|
27
|
+
[parentValues, attributes]
|
|
28
|
+
);
|
|
29
29
|
return /* @__PURE__ */ jsx(AnalyticsReactContext.Provider, { value: versionedCombinedValue, children });
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyticsContext.esm.js","sources":["../../src/analytics/AnalyticsContext.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createVersionedContext,\n createVersionedValueMap,\n} from '@backstage/version-bridge';\nimport { ComponentType, ReactNode, useContext } from 'react';\nimport { AnalyticsContextValue } from './types';\n\nconst AnalyticsReactContext = createVersionedContext<{\n 1: AnalyticsContextValue;\n}>('analytics-context');\n\n/**\n * A \"private\" (to this package) hook that enables context inheritance and a\n * way to read Analytics Context values at event capture-time.\n *\n * @internal\n */\nexport const useAnalyticsContext = (): AnalyticsContextValue => {\n const theContext = useContext(AnalyticsReactContext);\n\n // Provide a default value if no value exists.\n if (theContext === undefined) {\n return
|
|
1
|
+
{"version":3,"file":"AnalyticsContext.esm.js","sources":["../../src/analytics/AnalyticsContext.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n createVersionedContext,\n createVersionedValueMap,\n} from '@backstage/version-bridge';\nimport { ComponentType, ReactNode, useContext, useMemo } from 'react';\nimport { AnalyticsContextValue } from './types';\n\nconst AnalyticsReactContext = createVersionedContext<{\n 1: AnalyticsContextValue;\n}>('analytics-context');\n\nconst defaultAnalyticsContext: AnalyticsContextValue = Object.freeze({\n routeRef: 'unknown',\n pluginId: 'root',\n extension: 'App',\n});\n\n/**\n * A \"private\" (to this package) hook that enables context inheritance and a\n * way to read Analytics Context values at event capture-time.\n *\n * @internal\n */\nexport const useAnalyticsContext = (): AnalyticsContextValue => {\n const theContext = useContext(AnalyticsReactContext);\n\n // Provide a default value if no value exists.\n if (theContext === undefined) {\n return defaultAnalyticsContext;\n }\n\n // This should probably never happen, but check for it.\n const theValue = theContext.atVersion(1);\n if (theValue === undefined) {\n throw new Error('No context found for version 1.');\n }\n\n return theValue;\n};\n\n/**\n * Provides components in the child react tree an Analytics Context, ensuring\n * all analytics events captured within the context have relevant attributes.\n *\n * @remarks\n *\n * Analytics contexts are additive, meaning the context ultimately emitted with\n * an event is the combination of all contexts in the parent tree.\n *\n * @public\n */\nexport const AnalyticsContext = (options: {\n attributes: Partial<AnalyticsContextValue>;\n children: ReactNode;\n}) => {\n const { attributes, children } = options;\n\n const parentValues = useAnalyticsContext();\n // The versioned value is memoized so that context consumers don't get\n // rerendered when this provider rerenders without the attributes having\n // changed. Note that this requires callers to pass a stable attributes\n // object for the memoization to be effective.\n const versionedCombinedValue = useMemo(\n () => createVersionedValueMap({ 1: { ...parentValues, ...attributes } }),\n [parentValues, attributes],\n );\n return (\n <AnalyticsReactContext.Provider value={versionedCombinedValue}>\n {children}\n </AnalyticsReactContext.Provider>\n );\n};\n\n/**\n * Returns an HOC wrapping the provided component in an Analytics context with\n * the given values.\n *\n * @param Component - Component to be wrapped with analytics context attributes\n * @param values - Analytics context key/value pairs.\n * @internal\n */\nexport function withAnalyticsContext<TProps extends {}>(\n Component: ComponentType<TProps>,\n values: AnalyticsContextValue,\n) {\n const ComponentWithAnalyticsContext = (props: TProps) => {\n return (\n <AnalyticsContext attributes={values}>\n <Component {...props} />\n </AnalyticsContext>\n );\n };\n ComponentWithAnalyticsContext.displayName = `WithAnalyticsContext(${\n Component.displayName || Component.name || 'Component'\n })`;\n return ComponentWithAnalyticsContext;\n}\n"],"names":[],"mappings":";;;;AAuBA,MAAM,qBAAA,GAAwB,uBAE3B,mBAAmB,CAAA;AAEtB,MAAM,uBAAA,GAAiD,OAAO,MAAA,CAAO;AAAA,EACnE,QAAA,EAAU,SAAA;AAAA,EACV,QAAA,EAAU,MAAA;AAAA,EACV,SAAA,EAAW;AACb,CAAC,CAAA;AAQM,MAAM,sBAAsB,MAA6B;AAC9D,EAAA,MAAM,UAAA,GAAa,WAAW,qBAAqB,CAAA;AAGnD,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAO,uBAAA;AAAA,EACT;AAGA,EAAA,MAAM,QAAA,GAAW,UAAA,CAAW,SAAA,CAAU,CAAC,CAAA;AACvC,EAAA,IAAI,aAAa,MAAA,EAAW;AAC1B,IAAA,MAAM,IAAI,MAAM,iCAAiC,CAAA;AAAA,EACnD;AAEA,EAAA,OAAO,QAAA;AACT;AAaO,MAAM,gBAAA,GAAmB,CAAC,OAAA,KAG3B;AACJ,EAAA,MAAM,EAAE,UAAA,EAAY,QAAA,EAAS,GAAI,OAAA;AAEjC,EAAA,MAAM,eAAe,mBAAA,EAAoB;AAKzC,EAAA,MAAM,sBAAA,GAAyB,OAAA;AAAA,IAC7B,MAAM,uBAAA,CAAwB,EAAE,CAAA,EAAG,EAAE,GAAG,YAAA,EAAc,GAAG,UAAA,EAAW,EAAG,CAAA;AAAA,IACvE,CAAC,cAAc,UAAU;AAAA,GAC3B;AACA,EAAA,2BACG,qBAAA,CAAsB,QAAA,EAAtB,EAA+B,KAAA,EAAO,wBACpC,QAAA,EACH,CAAA;AAEJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/core-plugin-api",
|
|
3
|
-
"version": "1.12.9
|
|
3
|
+
"version": "1.12.9",
|
|
4
4
|
"description": "Core API used by Backstage plugins",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "web-library"
|
|
@@ -57,18 +57,18 @@
|
|
|
57
57
|
"test": "backstage-cli package test"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@backstage/config": "1.3.8",
|
|
61
|
-
"@backstage/errors": "1.3.1",
|
|
62
|
-
"@backstage/frontend-plugin-api": "0.18.0
|
|
63
|
-
"@backstage/types": "1.2.2",
|
|
64
|
-
"@backstage/version-bridge": "1.0.12",
|
|
60
|
+
"@backstage/config": "^1.3.8",
|
|
61
|
+
"@backstage/errors": "^1.3.1",
|
|
62
|
+
"@backstage/frontend-plugin-api": "^0.18.0",
|
|
63
|
+
"@backstage/types": "^1.2.2",
|
|
64
|
+
"@backstage/version-bridge": "^1.0.12",
|
|
65
65
|
"history": "^5.0.0",
|
|
66
66
|
"zod": "^3.25.76 || ^4.0.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@backstage/cli": "0.36.5
|
|
70
|
-
"@backstage/core-app-api": "1.20.4
|
|
71
|
-
"@backstage/test-utils": "1.7.21
|
|
69
|
+
"@backstage/cli": "^0.36.5",
|
|
70
|
+
"@backstage/core-app-api": "^1.20.4",
|
|
71
|
+
"@backstage/test-utils": "^1.7.21",
|
|
72
72
|
"@testing-library/dom": "^10.0.0",
|
|
73
73
|
"@testing-library/jest-dom": "^6.0.0",
|
|
74
74
|
"@testing-library/react": "^16.0.0",
|