diff --git a/.changeset/common-parrots-wink.md b/.changeset/common-parrots-wink.md new file mode 100644 index 0000000000..7e3578771b --- /dev/null +++ b/.changeset/common-parrots-wink.md @@ -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. diff --git a/plugins/techdocs-react/src/alpha.ts b/plugins/techdocs-react/src/alpha.ts index 689ec41977..130479561a 100644 --- a/plugins/techdocs-react/src/alpha.ts +++ b/plugins/techdocs-react/src/alpha.ts @@ -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 =

( techDocsAddon: ComponentType

, data: TechDocsAddonOptions, ) => { - attachComponentData(techDocsAddon, TECHDOCS_ADDONS_KEY, data); - attachComponentData(techDocsAddon, getDataKeyByName(data.name), true); + const element = React.createElement(techDocsAddon as ComponentType); + + const isDataAttached = getComponentData( + element, + TECHDOCS_ADDONS_KEY, + ); + if (!isDataAttached) { + attachComponentData(techDocsAddon, TECHDOCS_ADDONS_KEY, data); + } + + const dataKey = getDataKeyByName(data.name); + const isDataKeyAttached = getComponentData(element, dataKey); + if (!isDataKeyAttached) { + attachComponentData(techDocsAddon, dataKey, true); + } };