@treelocator/runtime 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browserApi.d.ts +45 -0
- package/dist/browserApi.js +23 -1
- package/dist/components/RecordingOutline.d.ts +5 -0
- package/dist/components/RecordingOutline.js +53 -0
- package/dist/components/RecordingResults.d.ts +25 -0
- package/dist/components/RecordingResults.js +272 -0
- package/dist/components/Runtime.js +505 -70
- package/dist/dejitter/recorder.d.ts +91 -0
- package/dist/dejitter/recorder.js +908 -0
- package/dist/functions/enrichAncestrySourceMaps.js +9 -2
- package/dist/functions/formatAncestryChain.js +27 -7
- package/dist/functions/formatAncestryChain.test.js +114 -0
- package/dist/functions/getUsableName.js +24 -2
- package/dist/output.css +13 -0
- package/package.json +2 -2
- package/src/browserApi.ts +74 -1
- package/src/components/RecordingOutline.tsx +66 -0
- package/src/components/RecordingResults.tsx +287 -0
- package/src/components/Runtime.tsx +534 -80
- package/src/dejitter/recorder.ts +938 -0
- package/src/functions/enrichAncestrySourceMaps.ts +9 -2
- package/src/functions/formatAncestryChain.test.ts +123 -0
- package/src/functions/formatAncestryChain.ts +28 -7
- package/src/functions/getUsableName.ts +24 -2
- package/.turbo/turbo-build.log +0 -32
- package/.turbo/turbo-dev.log +0 -32
- package/.turbo/turbo-test.log +0 -14
- package/.turbo/turbo-ts.log +0 -4
- package/LICENSE +0 -22
|
@@ -4,6 +4,8 @@ import { normalizeFilePath } from "./normalizeFilePath";
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Check if any DOM element has React 19 fibers (with _debugStack instead of _debugSource).
|
|
7
|
+
* Must walk the _debugOwner chain because DOM element fibers (HostComponent) never have
|
|
8
|
+
* _debugStack — only function component fibers do.
|
|
7
9
|
*/
|
|
8
10
|
function isReact19Environment(): boolean {
|
|
9
11
|
const el = document.querySelector("[class]") || document.body;
|
|
@@ -12,8 +14,13 @@ function isReact19Environment(): boolean {
|
|
|
12
14
|
const fiberKey = Object.keys(el).find((k) => k.startsWith("__reactFiber$"));
|
|
13
15
|
if (!fiberKey) return false;
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
let fiber = (el as any)[fiberKey];
|
|
18
|
+
while (fiber) {
|
|
19
|
+
if (fiber._debugSource) return false; // React 18
|
|
20
|
+
if ((fiber as any)._debugStack) return true; // React 19
|
|
21
|
+
fiber = fiber._debugOwner || null;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
/**
|
|
@@ -143,4 +143,127 @@ describe("formatAncestryChain", () => {
|
|
|
143
143
|
// Single component becomes the display name, no "in X" needed
|
|
144
144
|
expect(result).toBe("Button at src/Button.tsx:10");
|
|
145
145
|
});
|
|
146
|
+
|
|
147
|
+
describe("Anonymous component filtering", () => {
|
|
148
|
+
it("filters Anonymous from outer components in 'in X > Y' display", () => {
|
|
149
|
+
const items: AncestryItem[] = [
|
|
150
|
+
{
|
|
151
|
+
elementName: "div",
|
|
152
|
+
nthChild: 2,
|
|
153
|
+
componentName: "Anonymous",
|
|
154
|
+
filePath: "app/page.tsx",
|
|
155
|
+
line: 82,
|
|
156
|
+
ownerComponents: [
|
|
157
|
+
{ name: "Anonymous" },
|
|
158
|
+
{ name: "Home", filePath: "app/page.tsx", line: 82 },
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
{ elementName: "div", componentName: "App", filePath: "src/App.tsx", line: 1 },
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
const result = formatAncestryChain(items);
|
|
165
|
+
// "Anonymous" should be filtered out — just "Home" as display name, no "in Anonymous"
|
|
166
|
+
expect(result).toBe(
|
|
167
|
+
`App at src/App.tsx:1
|
|
168
|
+
└─ Home:nth-child(2) at app/page.tsx:82`
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("filters Anonymous from component boundary detection", () => {
|
|
173
|
+
// When prev item's innermost component is Anonymous, it shouldn't count
|
|
174
|
+
// as a different component from the current item
|
|
175
|
+
const items: AncestryItem[] = [
|
|
176
|
+
{
|
|
177
|
+
elementName: "p",
|
|
178
|
+
componentName: "Home",
|
|
179
|
+
filePath: "app/page.tsx",
|
|
180
|
+
line: 100,
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
elementName: "div",
|
|
184
|
+
componentName: "Anonymous",
|
|
185
|
+
filePath: "app/page.tsx",
|
|
186
|
+
line: 82,
|
|
187
|
+
ownerComponents: [
|
|
188
|
+
{ name: "Anonymous" },
|
|
189
|
+
{ name: "Home", filePath: "app/page.tsx", line: 82 },
|
|
190
|
+
],
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
const result = formatAncestryChain(items);
|
|
195
|
+
// Both items resolve to "Home" — no boundary crossing, so element name for child
|
|
196
|
+
expect(result).toBe(
|
|
197
|
+
`Home at app/page.tsx:82
|
|
198
|
+
└─ p at app/page.tsx:100`
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("handles all-Anonymous owner chain gracefully", () => {
|
|
203
|
+
const items: AncestryItem[] = [
|
|
204
|
+
{
|
|
205
|
+
elementName: "div",
|
|
206
|
+
componentName: "Anonymous",
|
|
207
|
+
filePath: "app/layout.tsx",
|
|
208
|
+
line: 10,
|
|
209
|
+
ownerComponents: [
|
|
210
|
+
{ name: "Anonymous" },
|
|
211
|
+
{ name: "Anonymous" },
|
|
212
|
+
],
|
|
213
|
+
},
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
const result = formatAncestryChain(items);
|
|
217
|
+
// All components are Anonymous — falls back to element name
|
|
218
|
+
expect(result).toBe("div at app/layout.tsx:10");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("skips Anonymous-only componentName without ownerComponents", () => {
|
|
222
|
+
const items: AncestryItem[] = [
|
|
223
|
+
{
|
|
224
|
+
elementName: "main",
|
|
225
|
+
componentName: "Anonymous",
|
|
226
|
+
filePath: "app/page.tsx",
|
|
227
|
+
line: 50,
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
elementName: "div",
|
|
231
|
+
componentName: "App",
|
|
232
|
+
filePath: "src/App.tsx",
|
|
233
|
+
line: 1,
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
|
|
237
|
+
const result = formatAncestryChain(items);
|
|
238
|
+
// "Anonymous" componentName should not be used as display name
|
|
239
|
+
expect(result).toBe(
|
|
240
|
+
`App at src/App.tsx:1
|
|
241
|
+
└─ main at app/page.tsx:50`
|
|
242
|
+
);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("preserves named components when mixed with Anonymous", () => {
|
|
246
|
+
const items: AncestryItem[] = [
|
|
247
|
+
{
|
|
248
|
+
elementName: "div",
|
|
249
|
+
componentName: "Sidebar",
|
|
250
|
+
filePath: "src/Sidebar.tsx",
|
|
251
|
+
line: 20,
|
|
252
|
+
ownerComponents: [
|
|
253
|
+
{ name: "Sidebar", filePath: "src/Sidebar.tsx", line: 20 },
|
|
254
|
+
{ name: "Anonymous" },
|
|
255
|
+
{ name: "GlassPanel", filePath: "src/GlassPanel.tsx", line: 5 },
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
{ elementName: "div", componentName: "App", filePath: "src/App.tsx", line: 1 },
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
const result = formatAncestryChain(items);
|
|
262
|
+
// Anonymous in the middle is filtered, Sidebar (outer) and GlassPanel (inner) remain
|
|
263
|
+
expect(result).toBe(
|
|
264
|
+
`App at src/App.tsx:1
|
|
265
|
+
└─ GlassPanel in Sidebar at src/Sidebar.tsx:20`
|
|
266
|
+
);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
146
269
|
});
|
|
@@ -147,6 +147,23 @@ export function collectAncestry(node: TreeNode): AncestryItem[] {
|
|
|
147
147
|
return items;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
function getInnermostNamedComponent(item: AncestryItem | null | undefined): string | undefined {
|
|
151
|
+
if (!item) return undefined;
|
|
152
|
+
if (item.ownerComponents && item.ownerComponents.length > 0) {
|
|
153
|
+
// Find the innermost non-Anonymous component
|
|
154
|
+
for (let i = item.ownerComponents.length - 1; i >= 0; i--) {
|
|
155
|
+
if (item.ownerComponents[i]!.name !== "Anonymous") {
|
|
156
|
+
return item.ownerComponents[i]!.name;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Fall back to componentName if it's not Anonymous
|
|
161
|
+
if (item.componentName && item.componentName !== "Anonymous") {
|
|
162
|
+
return item.componentName;
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
|
|
150
167
|
export function formatAncestryChain(items: AncestryItem[]): string {
|
|
151
168
|
if (items.length === 0) {
|
|
152
169
|
return "";
|
|
@@ -162,11 +179,12 @@ export function formatAncestryChain(items: AncestryItem[]): string {
|
|
|
162
179
|
const prefix = index === 0 ? "" : "└─ ";
|
|
163
180
|
|
|
164
181
|
// Get the previous item's component to detect component boundaries
|
|
182
|
+
// Ignore "Anonymous" when resolving component names — these are framework internals
|
|
165
183
|
const prevItem = index > 0 ? reversed[index - 1] : null;
|
|
166
|
-
const prevComponentName = prevItem
|
|
184
|
+
const prevComponentName = getInnermostNamedComponent(prevItem);
|
|
167
185
|
|
|
168
|
-
// Get current item's innermost component
|
|
169
|
-
const currentComponentName = item
|
|
186
|
+
// Get current item's innermost named component
|
|
187
|
+
const currentComponentName = getInnermostNamedComponent(item);
|
|
170
188
|
|
|
171
189
|
// Determine the display name for the element
|
|
172
190
|
// Use component name ONLY when crossing a component boundary (root element of a component)
|
|
@@ -177,14 +195,17 @@ export function formatAncestryChain(items: AncestryItem[]): string {
|
|
|
177
195
|
|
|
178
196
|
if (isComponentBoundary) {
|
|
179
197
|
if (item.ownerComponents && item.ownerComponents.length > 0) {
|
|
180
|
-
// Use innermost component as display name, show outer ones in "in X > Y"
|
|
181
|
-
|
|
198
|
+
// Use innermost named component as display name, show outer ones in "in X > Y"
|
|
199
|
+
// Filter out "Anonymous" components — these are framework-internal wrappers
|
|
200
|
+
// (e.g. Next.js App Router) that add noise without useful context
|
|
201
|
+
const named = item.ownerComponents.filter((c) => c.name !== "Anonymous");
|
|
202
|
+
const innermost = named[named.length - 1];
|
|
182
203
|
if (innermost) {
|
|
183
204
|
displayName = innermost.name;
|
|
184
205
|
// Outer components (excluding innermost)
|
|
185
|
-
outerComponents =
|
|
206
|
+
outerComponents = named.slice(0, -1).map((c) => c.name);
|
|
186
207
|
}
|
|
187
|
-
} else if (item.componentName) {
|
|
208
|
+
} else if (item.componentName && item.componentName !== "Anonymous") {
|
|
188
209
|
displayName = item.componentName;
|
|
189
210
|
}
|
|
190
211
|
}
|
|
@@ -36,17 +36,39 @@ export function getUsableName(fiber: Fiber | null | undefined): string {
|
|
|
36
36
|
if (fiber.elementType.name) {
|
|
37
37
|
return fiber.elementType.name;
|
|
38
38
|
}
|
|
39
|
-
// Not sure about this
|
|
40
39
|
if (fiber.elementType.displayName) {
|
|
41
40
|
return fiber.elementType.displayName;
|
|
42
41
|
}
|
|
43
|
-
// Used in
|
|
42
|
+
// Used in React.memo
|
|
44
43
|
if (fiber.elementType.type?.name) {
|
|
45
44
|
return fiber.elementType.type.name;
|
|
46
45
|
}
|
|
46
|
+
if (fiber.elementType.type?.displayName) {
|
|
47
|
+
return fiber.elementType.type.displayName;
|
|
48
|
+
}
|
|
49
|
+
// React.forwardRef wraps the render function in .render
|
|
50
|
+
if (fiber.elementType.render?.name) {
|
|
51
|
+
return fiber.elementType.render.name;
|
|
52
|
+
}
|
|
53
|
+
if (fiber.elementType.render?.displayName) {
|
|
54
|
+
return fiber.elementType.render.displayName;
|
|
55
|
+
}
|
|
56
|
+
// React lazy components store resolved module in _payload._result
|
|
47
57
|
if (fiber.elementType._payload?._result?.name) {
|
|
48
58
|
return fiber.elementType._payload._result.name;
|
|
49
59
|
}
|
|
60
|
+
if (fiber.elementType._payload?._result?.displayName) {
|
|
61
|
+
return fiber.elementType._payload._result.displayName;
|
|
62
|
+
}
|
|
63
|
+
// fiber.type can differ from elementType in some React internals
|
|
64
|
+
if (fiber.type && typeof fiber.type !== "string" && fiber.type !== fiber.elementType) {
|
|
65
|
+
if (fiber.type.name) {
|
|
66
|
+
return fiber.type.name;
|
|
67
|
+
}
|
|
68
|
+
if (fiber.type.displayName) {
|
|
69
|
+
return fiber.type.displayName;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
50
72
|
|
|
51
73
|
return "Anonymous";
|
|
52
74
|
}
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @treelocator/runtime@0.3.1 build /Users/wende/projects/treelocatorjs/packages/runtime
|
|
3
|
-
> concurrently pnpm:build:*
|
|
4
|
-
|
|
5
|
-
[wrapImage]
|
|
6
|
-
[wrapImage] > @treelocator/runtime@0.3.1 build:wrapImage /Users/wende/projects/treelocatorjs/packages/runtime
|
|
7
|
-
[wrapImage] > node ./scripts/wrapImage.js
|
|
8
|
-
[wrapImage]
|
|
9
|
-
[ts]
|
|
10
|
-
[ts] > @treelocator/runtime@0.3.1 build:ts /Users/wende/projects/treelocatorjs/packages/runtime
|
|
11
|
-
[ts] > tsc --declaration --emitDeclarationOnly --noEmit false --outDir dist
|
|
12
|
-
[ts]
|
|
13
|
-
[babel]
|
|
14
|
-
[babel] > @treelocator/runtime@0.3.1 build:babel /Users/wende/projects/treelocatorjs/packages/runtime
|
|
15
|
-
[babel] > babel src --out-dir dist --extensions .js,.jsx,.ts,.tsx
|
|
16
|
-
[babel]
|
|
17
|
-
[tailwind]
|
|
18
|
-
[tailwind] > @treelocator/runtime@0.3.1 build:tailwind /Users/wende/projects/treelocatorjs/packages/runtime
|
|
19
|
-
[tailwind] > tailwindcss -i ./src/main.css -o ./dist/output.css
|
|
20
|
-
[tailwind]
|
|
21
|
-
[wrapImage] Tree icon file generated
|
|
22
|
-
[wrapImage] pnpm run build:wrapImage exited with code 0
|
|
23
|
-
[babel] [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
|
|
24
|
-
[tailwind] [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
|
|
25
|
-
[tailwind]
|
|
26
|
-
[tailwind] Rebuilding...
|
|
27
|
-
[tailwind]
|
|
28
|
-
[tailwind] Done in 175ms.
|
|
29
|
-
[tailwind] pnpm run build:tailwind exited with code 0
|
|
30
|
-
[babel] Successfully compiled 82 files with Babel (602ms).
|
|
31
|
-
[babel] pnpm run build:babel exited with code 0
|
|
32
|
-
[ts] pnpm run build:ts exited with code 0
|
package/.turbo/turbo-dev.log
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @treelocator/runtime@0.1.8 dev /Users/wende/projects/locatorjs/packages/runtime
|
|
3
|
-
> concurrently pnpm:dev:*
|
|
4
|
-
|
|
5
|
-
[babel]
|
|
6
|
-
[babel] > @treelocator/runtime@0.1.8 dev:babel /Users/wende/projects/locatorjs/packages/runtime
|
|
7
|
-
[babel] > babel src --watch --out-dir dist --extensions .js,.jsx,.ts,.tsx
|
|
8
|
-
[babel]
|
|
9
|
-
[wrapImage]
|
|
10
|
-
[wrapImage] > @treelocator/runtime@0.1.8 dev:wrapImage /Users/wende/projects/locatorjs/packages/runtime
|
|
11
|
-
[wrapImage] > WATCH=true node ./scripts/wrapImage.js
|
|
12
|
-
[wrapImage]
|
|
13
|
-
[ts]
|
|
14
|
-
[ts] > @treelocator/runtime@0.1.8 dev:ts /Users/wende/projects/locatorjs/packages/runtime
|
|
15
|
-
[ts] > tsc --watch --declaration --emitDeclarationOnly --noEmit false --outDir dist --preserveWatchOutput
|
|
16
|
-
[ts]
|
|
17
|
-
[wrapCSS]
|
|
18
|
-
[wrapCSS] > @treelocator/runtime@0.1.8 dev:wrapCSS /Users/wende/projects/locatorjs/packages/runtime
|
|
19
|
-
[wrapCSS] > WATCH=true node ./scripts/wrapCSS.js
|
|
20
|
-
[wrapCSS]
|
|
21
|
-
[tailwind]
|
|
22
|
-
[tailwind] > @treelocator/runtime@0.1.8 dev:tailwind /Users/wende/projects/locatorjs/packages/runtime
|
|
23
|
-
[tailwind] > tailwindcss -i ./src/main.css -o ./dist/output.css --watch
|
|
24
|
-
[tailwind]
|
|
25
|
-
[tailwind] ELIFECYCLE Command failed.
|
|
26
|
-
[ts] ELIFECYCLE Command failed.
|
|
27
|
-
[wrapImage] ELIFECYCLE Command failed.
|
|
28
|
-
[wrapCSS] ELIFECYCLE Command failed.
|
|
29
|
-
[babel] ELIFECYCLE Command failed.
|
|
30
|
-
[babel] pnpm run dev:babel exited with code SIGINT
|
|
31
|
-
[wrapCSS] pnpm run dev:wrapCSS exited with code SIGINT
|
|
32
|
-
[wrapImage] pnpm run dev:wrapImage exited with code SIGINT
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @treelocator/runtime@0.3.0 test /Users/wende/projects/treelocatorjs/packages/runtime
|
|
3
|
-
> vitest run
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
RUN v2.1.9 /Users/wende/projects/treelocatorjs/packages/runtime
|
|
7
|
-
|
|
8
|
-
✓ src/functions/formatAncestryChain.test.ts (9 tests) 2ms
|
|
9
|
-
✓ src/functions/evalTemplate.test.ts (1 test) 1ms
|
|
10
|
-
✓ src/functions/cropPath.test.ts (2 tests) 1ms
|
|
11
|
-
✓ src/functions/mergeRects.test.ts (1 test) 1ms
|
|
12
|
-
✓ src/functions/getUsableFileName.test.tsx (4 tests) 2ms
|
|
13
|
-
✓ src/functions/transformPath.test.ts (3 tests) 6ms
|
|
14
|
-
ELIFECYCLE Test failed. See above for more details.
|
package/.turbo/turbo-ts.log
DELETED
package/LICENSE
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Krzysztof Wende
|
|
4
|
-
Copyright (c) 2023 Michael Musil (original LocatorJS)
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|