Skip to content

Commit

Permalink
core-api: remove duplicate element check during traversal
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
  • Loading branch information
Rugvip committed Mar 18, 2021
1 parent e1bd13d commit e7f9b94
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-birds-attack.md
@@ -0,0 +1,5 @@
---
'@backstage/core-api': patch
---

Allow elements to be used multiple times in the app element tree.
9 changes: 0 additions & 9 deletions packages/core-api/src/extensions/traversal.ts
Expand Up @@ -37,7 +37,6 @@ export function traverseElementTree<Results>(options: {
discoverers: Discoverer[];
collectors: { [name in keyof Results]: Collector<Results[name], any> };
}): Results {
const visited = new Set();
const collectors: {
[name in string]: ReturnType<Collector<any, any>>;
} = {};
Expand Down Expand Up @@ -74,14 +73,6 @@ export function traverseElementTree<Results>(options: {
if (!isValidElement(element)) {
return;
}
if (visited.has(element)) {
const anyType = element?.type as
| { displayName?: string; name?: string }
| undefined;
const name = anyType?.displayName || anyType?.name || String(anyType);
throw new Error(`Visited element ${name} twice`);
}
visited.add(element);

const nextContexts: QueueItem['contexts'] = {};

Expand Down
20 changes: 0 additions & 20 deletions packages/core-api/src/routing/collectors.test.tsx
Expand Up @@ -353,24 +353,4 @@ describe('discovery', () => {
});
}).toThrow('Mounted routable extension must have a path');
});

it('should not visit the same element twice', () => {
const element = <Extension3 path="/baz" />;

expect(() =>
traverseElementTree({
root: (
<MemoryRouter>
<Extension1 path="/foo">{element}</Extension1>
<Extension2 path="/bar">{element}</Extension2>
</MemoryRouter>
),
discoverers: [childDiscoverer, routeElementDiscoverer],
collectors: {
routes: routePathCollector,
routeParents: routeParentCollector,
},
}),
).toThrow(`Visited element Extension(Component) twice`);
});
});

0 comments on commit e7f9b94

Please sign in to comment.