Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/components/icon/icon-state.broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ export class IconsStateBroadcast {

this.send({
actionType: ActionType.SyncState,
collections: this._getUserSetCollection(this._iconsCollection),
references: this._getUserRefsCollection(this._iconReferences),
collections: this._getUserSetCollection(
this._iconsCollection.toPlainMap()
),
references: this._getUserRefsCollection(
this._iconReferences.toPlainMap()
),
origin: IconsStateBroadcast._origin,
});
}
Expand All @@ -104,7 +108,7 @@ export class IconsStateBroadcast {
}

private _getUserRefsCollection(
collections: IconsCollection<IconMeta>
collections: Map<string, Map<string, IconMeta>>
): IconsCollection<IconMeta> {
const userSetIcons = createIconDefaultMap<string, IconMeta>();

Expand All @@ -120,7 +124,7 @@ export class IconsStateBroadcast {
}

private _getUserSetCollection(
collections: IconsCollection<SvgIcon>
collections: Map<string, Map<string, SvgIcon>>
): IconsCollection<SvgIcon> {
const userSetIcons = createIconDefaultMap<string, SvgIcon>();

Expand Down
21 changes: 21 additions & 0 deletions src/components/icon/registry/default-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ class DefaultMap<K, V> extends Map<K, V> {

return this.get(key) as V;
}

/**
* Converts the DefaultMap to a plain Map for structured cloning.
*
* @remarks
* This method helps with cross-browser compatibility when using BroadcastChannel
* or postMessage, as custom Map subclasses are not properly cloned in Safari.
* Returns a plain Map that is guarantied to be structured cloneable across all browsers.
*
* @returns A plain Map with the same entries as this DefaultMap.
*
* @example
* ```typescript
* const defaultMap = new DefaultMap<string, Set<number>>();
* const plainMap = defaultMap.toPlainMap();
* channel.postMessage({ data: plainMap });
* ```
*/
public toPlainMap(): Map<K, V> {
return new Map(this.entries());
}
}

/**
Expand Down