From 9ff33225fe05d8355436e7e84427a160dc52fcaa Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 24 Jan 2025 00:29:33 +0100 Subject: [PATCH] frontend-plugin-api: allow duplicate route ref IDs Signed-off-by: Patrik Oldsberg --- .changeset/witty-pets-march.md | 5 +++++ packages/frontend-plugin-api/src/routing/RouteRef.test.ts | 1 + packages/frontend-plugin-api/src/routing/RouteRef.ts | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/witty-pets-march.md diff --git a/.changeset/witty-pets-march.md b/.changeset/witty-pets-march.md new file mode 100644 index 0000000000..163d146027 --- /dev/null +++ b/.changeset/witty-pets-march.md @@ -0,0 +1,5 @@ +--- +'@backstage/frontend-plugin-api': patch +--- + +Allow route references to be installed in multiple app instances as long as their name is the same. diff --git a/packages/frontend-plugin-api/src/routing/RouteRef.test.ts b/packages/frontend-plugin-api/src/routing/RouteRef.test.ts index de7a3de887..570723df9a 100644 --- a/packages/frontend-plugin-api/src/routing/RouteRef.test.ts +++ b/packages/frontend-plugin-api/src/routing/RouteRef.test.ts @@ -35,6 +35,7 @@ describe('RouteRef', () => { internal.setId('some-id'); expect(String(internal)).toBe('RouteRef{some-id}'); + internal.setId('some-id'); // Should allow same ID expect(() => internal.setId('some-other-id')).toThrow( "RouteRef was referenced twice as both 'some-id' and 'some-other-id'", diff --git a/packages/frontend-plugin-api/src/routing/RouteRef.ts b/packages/frontend-plugin-api/src/routing/RouteRef.ts index da562e5273..1678e14cd4 100644 --- a/packages/frontend-plugin-api/src/routing/RouteRef.ts +++ b/packages/frontend-plugin-api/src/routing/RouteRef.ts @@ -95,7 +95,7 @@ export class RouteRefImpl implements InternalRouteRef { if (!id) { throw new Error(`${this.#name} id must be a non-empty string`); } - if (this.#id) { + if (this.#id && this.#id !== id) { throw new Error( `${this.#name} was referenced twice as both '${this.#id}' and '${id}'`, );