Skip to content

Commit

Permalink
fix(ui5-toolbar): update ToolbarRegistry to use metadata tag instead …
Browse files Browse the repository at this point in the history
…of class name (#9607)

This change updates the registration mechanism for toolbar items to use a metadata tag instead of the class name. 

#### Changes:
- In `Toolbar.ts`, updated the `getItemsInfo` method to retrieve the registered toolbar item using `ctor.getMetadata().getPureTag()` instead of `item.constructor.name`.
- In `ToolbarRegistry.ts`, modified the `registerToolbarItem` function to register items with `ElementClass.getMetadata().getPureTag()` instead of `ElementClass.name`.

#### Issue Addressed:
In production builds, webpack minifies class names which resulted in all toolbar buttons being registered under the same name ("i"). This caused all toolbar items to be registered as the last one registered due to name conflicts. By switching to a more stable identifier from the class metadata, we prevent such issues.
  • Loading branch information
dobrinyonkov committed Aug 5, 2024
1 parent 3153e6e commit f03fbaf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/main/src/Toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ class Toolbar extends UI5Element {

getItemsInfo(items: Array<ToolbarItem>) {
return items.map((item: ToolbarItem) => {
const ElementClass = getRegisteredToolbarItem(item.constructor.name);
const ctor = item.constructor as typeof ToolbarItem;
const ElementClass = getRegisteredToolbarItem(ctor.getMetadata().getPureTag());

if (!ElementClass) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/ToolbarRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type ToolbarItem from "./ToolbarItem.js";
const registry = getSharedResource<Map<string, typeof ToolbarItem>>("ToolbarItem.registry", new Map());

const registerToolbarItem = (ElementClass: typeof ToolbarItem) => {
registry.set(ElementClass.name, ElementClass);
registry.set(ElementClass.getMetadata().getPureTag(), ElementClass);
};

const getRegisteredToolbarItem = (name: string) => {
Expand Down

0 comments on commit f03fbaf

Please sign in to comment.