Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy displayName and name manually #535

Merged
merged 1 commit into from
Jan 29, 2025
Merged
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
9 changes: 6 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources:
}

export const copyComponentProperties = (Component: any, UnistylesComponent: any) => {
Object.entries(Object.getOwnPropertyDescriptors(Component)).forEach(([key, propertyDescriptor]) => {
Object.entries(Component).forEach(([key, value]) => {
// Filter out the keys we don't want to copy
if (['$$typeof', 'render'].includes(key)) {
return
}

// @ts-expect-error Copy extra component properties - example: Image.getSize, Image.displayName
UnistylesComponent[key] = propertyDescriptor.value ?? propertyDescriptor.get()
UnistylesComponent[key] = value
})

// Those are not enumerable, so we need to copy them manually
UnistylesComponent.displayName = Component.displayName
UnistylesComponent.name = Component.name

return UnistylesComponent
}