Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/fresh-astro-compiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/astro': patch
---

Fix custom user button menu item rendering for Astro's stricter compiler.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,55 @@ const isDevMode = import.meta.env.DEV;
`Clerk: <UserButton.MenuItems /> component can only accept <UserButton.Action /> and <UserButton.Link /> as its children. Any other provided component will be ignored.`,
);
}
return;
}
} else {
// Get the user button map from window that we set in the `<InternalUIComponentRenderer />`.
const userButtonComponentMap = window.__astro_clerk_component_props?.get('user-button');

// Get the user button map from window that we set in the `<InternalUIComponentRenderer />`.
const userButtonComponentMap = window.__astro_clerk_component_props.get('user-button');
let userButton;
if (parent) {
userButton = document.querySelector(`[data-clerk-id="clerk-user-button-${parent}"]`);
} else {
userButton = document.querySelector('[data-clerk-id^="clerk-user-button"]');
}

let userButton;
if (parent) {
userButton = document.querySelector(`[data-clerk-id="clerk-user-button-${parent}"]`);
} else {
userButton = document.querySelector('[data-clerk-id^="clerk-user-button"]');
}
const safeId = userButton?.getAttribute('data-clerk-id');
if (userButtonComponentMap && safeId) {
const currentOptions = userButtonComponentMap.get(safeId);

const safeId = userButton.getAttribute('data-clerk-id');
const currentOptions = userButtonComponentMap.get(safeId);
const reorderItemsLabels = ['manageAccount', 'signOut'];
const isReorderItem = reorderItemsLabels.includes(label);

const reorderItemsLabels = ['manageAccount', 'signOut'];
const isReorderItem = reorderItemsLabels.includes(label);
let newMenuItem = {
label,
};

let newMenuItem = {
label,
};
if (!isReorderItem) {
newMenuItem = {
...newMenuItem,
mountIcon: el => {
el.innerHTML = labelIcon;
},
unmountIcon: () => {
/* What to clean up? */
},
};

if (!isReorderItem) {
newMenuItem = {
...newMenuItem,
mountIcon: el => {
el.innerHTML = labelIcon;
},
unmountIcon: () => {
/* What to clean up? */
},
};
if (href) {
newMenuItem.href = href;
} else if (open) {
newMenuItem.open = open.startsWith('/') ? open : `/${open}`;
} else if (clickIdentifier) {
const clickEvent = new CustomEvent('clerk:menu-item-click', { detail: clickIdentifier });
newMenuItem.onClick = () => {
document.dispatchEvent(clickEvent);
};
}
}

if (href) {
newMenuItem.href = href;
} else if (open) {
newMenuItem.open = open.startsWith('/') ? open : `/${open}`;
} else if (clickIdentifier) {
const clickEvent = new CustomEvent('clerk:menu-item-click', { detail: clickIdentifier });
newMenuItem.onClick = () => {
document.dispatchEvent(clickEvent);
};
userButtonComponentMap.set(safeId, {
...currentOptions,
customMenuItems: [...(currentOptions?.customMenuItems ?? []), newMenuItem],
});
}
}

userButtonComponentMap.set(safeId, {
...currentOptions,
customMenuItems: [...(currentOptions?.customMenuItems ?? []), newMenuItem],
});
</script>
Loading