Skip to content

Commit 4f31c75

Browse files
committed
Support Comp.displayName for component names
1 parent d1657b4 commit 4f31c75

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

.changeset/odd-mangos-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solid-devtools/debugger": patch
3+
---
4+
5+
Use Component.displayName for component names if present.

examples/sandbox/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const Broken: s.Component = () => {
115115

116116
const createComponent = (content: () => s.JSX.Element) => {
117117
const Content = () => <div>{content()}</div>
118+
Content.displayName = 'createComponent.Content'
118119
return Content
119120
}
120121

packages/debugger/src/main/utils.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,40 @@ export const getOwnerType = (o: Readonly<Solid.Owner>): NodeType => {
7373
return NodeType.Computation
7474
}
7575

76-
export const getNodeName = (o: {name?: string}): string | undefined => {
77-
if (!o.name) return
78-
let name = o.name
79-
if (name.startsWith(SOLID_REFRESH_PREFIX)) name = name.slice(SOLID_REFRESH_PREFIX.length)
80-
return trimString(name, 20)
76+
export const getNodeName = (o: {
77+
component?: ((..._: any) => any) & {displayName?: string},
78+
name?: string
79+
}): string | undefined => {
80+
81+
let name: string | undefined
82+
83+
search: {
84+
if (typeof o.component === 'function') {
85+
if (typeof o.component.displayName === 'string' && o.component.displayName.length > 0) {
86+
name = o.component.displayName
87+
break search
88+
}
89+
if (typeof o.component.name === 'string' && o.component.name.length > 0) {
90+
name = o.component.name
91+
break search
92+
}
93+
}
94+
95+
if (o.name != null && o.name.length > 0) {
96+
name = o.name
97+
break search
98+
}
99+
100+
return undefined
101+
}
102+
103+
if (name.startsWith(SOLID_REFRESH_PREFIX)) {
104+
name = name.slice(SOLID_REFRESH_PREFIX.length)
105+
}
106+
107+
name = trimString(name, 36)
108+
109+
return name
81110
}
82111

83112
export function markOwnerType(o: Solid.Owner): NodeType {

0 commit comments

Comments
 (0)