diff --git a/packages/plugin-api/src/extensions/componentData.test.tsx b/packages/plugin-api/src/extensions/componentData.test.tsx
index 417fe07414..6c4abda40f 100644
--- a/packages/plugin-api/src/extensions/componentData.test.tsx
+++ b/packages/plugin-api/src/extensions/componentData.test.tsx
@@ -59,60 +59,4 @@ describe('elementData', () => {
'Attempted to attach duplicate data "my-data" to component "MyComponent"',
);
});
-
- describe('works across versions', () => {
- function getDataSymbol() {
- const Component = () => null;
- attachComponentData(Component, 'my-data', {});
- const [symbol] = Object.getOwnPropertySymbols(Component);
- return symbol;
- }
-
- it('should should be able to get data from older versions', () => {
- const symbol = getDataSymbol();
-
- const data = { foo: 'bar' };
- const Component = () => null;
- attachComponentData(Component, 'my-data', data);
-
- const element = ;
- expect((element as any).type[symbol].map.get('my-data')).toBe(data);
- });
-
- it('should should be able to attach data for older versions', () => {
- const symbol = getDataSymbol();
-
- const data = { foo: 'bar' };
- const Component = () => null;
- (Component as any)[symbol] = {
- map: new Map([['my-data', data]]),
- };
-
- const element = ;
- expect(getComponentData(element, 'my-data')).toBe(data);
- });
-
- it('should be able to get data from newer versions', () => {
- const data = { foo: 'bar' };
- const Component = () => null;
- attachComponentData(Component, 'my-data', data);
-
- const element = ;
- const container = (global as any)[
- '__@backstage/component-data-store__'
- ].get(element.type);
- expect(container.map.get('my-data')).toBe(data);
- });
-
- it('should should be able to attach data for newer versions', () => {
- const data = { foo: 'bar' };
- const Component = () => null;
- (global as any)['__@backstage/component-data-store__'].set(Component, {
- map: new Map([['my-data', data]]),
- });
-
- const element = ;
- expect(getComponentData(element, 'my-data')).toBe(data);
- });
- });
});
diff --git a/packages/plugin-api/src/extensions/componentData.tsx b/packages/plugin-api/src/extensions/componentData.tsx
index fc8594039c..f835ad38a8 100644
--- a/packages/plugin-api/src/extensions/componentData.tsx
+++ b/packages/plugin-api/src/extensions/componentData.tsx
@@ -17,23 +17,16 @@
import { ComponentType, ReactNode } from 'react';
import { getOrCreateGlobalSingleton } from '../lib/globalObject';
-// TODO(Rugvip): Access via symbol is deprecated, remove once on 0.3.x
-const DATA_KEY = Symbol('backstage-component-data');
-
-type ComponentWithData
= ComponentType
& {
- [DATA_KEY]?: DataContainer;
-};
-
type DataContainer = {
map: Map;
};
type MaybeComponentNode = ReactNode & {
- type?: ComponentType & { [DATA_KEY]?: DataContainer };
+ type?: ComponentType;
};
// The store is bridged across versions using the global object
-const store = getOrCreateGlobalSingleton(
+const globalStore = getOrCreateGlobalSingleton(
'component-data-store',
() => new WeakMap, DataContainer>(),
);
@@ -43,13 +36,10 @@ export function attachComponentData(
type: string,
data: unknown,
) {
- const dataComponent = component as ComponentWithData
;
-
- let container = store.get(component) || dataComponent[DATA_KEY];
+ let container = globalStore.get(component);
if (!container) {
container = { map: new Map() };
- store.set(component, container);
- dataComponent[DATA_KEY] = container;
+ globalStore.set(component, container);
}
if (container.map.has(type)) {
@@ -75,7 +65,7 @@ export function getComponentData(
return undefined;
}
- const container = store.get(component) || component[DATA_KEY];
+ const container = globalStore.get(component);
if (!container) {
return undefined;
}