techdocs: update attachTechDocsAddonComponentData with idempotency

Signed-off-by: Jackson Chen <jacksonc@spotify.com>
This commit is contained in:
Jackson Chen
2025-03-26 11:33:22 -04:00
parent a31a430c17
commit 0e9f7fe269
2 changed files with 25 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-react': patch
---
Fix catalog entity docs page not loading due to multiple addons data attachment in the New Frontend System.
+20 -3
View File
@@ -13,8 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { TechDocsAddonOptions } from './types';
import { attachComponentData } from '@backstage/core-plugin-api';
import {
attachComponentData,
getComponentData,
} from '@backstage/core-plugin-api';
import { ComponentType } from 'react';
import { getDataKeyByName, TECHDOCS_ADDONS_KEY } from './addons';
import {
@@ -53,6 +57,19 @@ export const attachTechDocsAddonComponentData = <P>(
techDocsAddon: ComponentType<P>,
data: TechDocsAddonOptions,
) => {
attachComponentData(techDocsAddon, TECHDOCS_ADDONS_KEY, data);
attachComponentData(techDocsAddon, getDataKeyByName(data.name), true);
const element = React.createElement(techDocsAddon as ComponentType);
const isDataAttached = getComponentData<TechDocsAddonOptions>(
element,
TECHDOCS_ADDONS_KEY,
);
if (!isDataAttached) {
attachComponentData(techDocsAddon, TECHDOCS_ADDONS_KEY, data);
}
const dataKey = getDataKeyByName(data.name);
const isDataKeyAttached = getComponentData<boolean>(element, dataKey);
if (!isDataKeyAttached) {
attachComponentData(techDocsAddon, dataKey, true);
}
};