Skip to content

Commit ae35870

Browse files
authored
Don't clone nodes as part of the debug event logger (#2635)
1 parent 8111d1e commit ae35870

4 files changed

Lines changed: 81 additions & 73 deletions

File tree

.changeset/weak-feet-invent.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'lit-html': patch
3+
'@lit/reactive-element': patch
4+
---
5+
6+
Make the event debug logger lazier, doing even less work (with no side effects) even in dev mode unless the page has opted in.

lit-next.code-workspace

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
{
2-
"folders": [
3-
{
4-
"name": "lit",
5-
"path": "packages/lit"
6-
},
7-
{
8-
"name": "lit-html",
9-
"path": "packages/lit-html"
10-
},
11-
{
12-
"name": "lit-element",
13-
"path": "packages/lit-element"
14-
},
15-
{
16-
"name": "reactive-element",
17-
"path": "packages/reactive-element"
18-
},
19-
{
20-
"name": "ssr",
21-
"path": "packages/labs/ssr"
22-
},
23-
{
24-
"name": "lit-starter-ts",
25-
"path": "packages/lit-starter-ts"
26-
},
27-
{
28-
"name": "lit-starter-js",
29-
"path": "packages/lit-starter-js"
30-
},
31-
{
32-
"name": "localize",
33-
"path": "packages/localize"
34-
},
35-
{
36-
"name": "labs",
37-
"path": "packages/labs"
38-
},
39-
{
40-
"name": "tests",
41-
"path": "packages/tests"
42-
},
43-
{
44-
"name": "benchmarks",
45-
"path": "packages/benchmarks"
46-
},
47-
{
48-
"name": "lit",
49-
"path": "."
50-
}
51-
],
52-
"settings": {
53-
"typescript.tsdk": "node_modules/typescript/lib",
54-
"debug.javascript.warnOnLongPrediction": false
55-
},
56-
"extensions": {
57-
"recommendations": [
58-
"dbaeumer.vscode-eslint",
59-
"esbenp.prettier-vscode"
60-
]
61-
}
2+
"folders": [
3+
{
4+
"name": "lit",
5+
"path": "packages/lit"
6+
},
7+
{
8+
"name": "lit-html",
9+
"path": "packages/lit-html"
10+
},
11+
{
12+
"name": "lit-element",
13+
"path": "packages/lit-element"
14+
},
15+
{
16+
"name": "reactive-element",
17+
"path": "packages/reactive-element"
18+
},
19+
{
20+
"name": "ssr",
21+
"path": "packages/labs/ssr"
22+
},
23+
{
24+
"name": "lit-starter-ts",
25+
"path": "packages/lit-starter-ts"
26+
},
27+
{
28+
"name": "lit-starter-js",
29+
"path": "packages/lit-starter-js"
30+
},
31+
{
32+
"name": "localize",
33+
"path": "packages/localize"
34+
},
35+
{
36+
"name": "labs",
37+
"path": "packages/labs"
38+
},
39+
{
40+
"name": "tests",
41+
"path": "packages/tests"
42+
},
43+
{
44+
"name": "benchmarks",
45+
"path": "packages/benchmarks"
46+
},
47+
{
48+
"name": "lit",
49+
"path": "."
50+
}
51+
],
52+
"settings": {
53+
"typescript.tsdk": "node_modules/typescript/lib",
54+
"debug.javascript.warnOnLongPrediction": false,
55+
// Regardless of the user's usual formatter, files
56+
// in the Lit repo must be formatted using prettier.
57+
"editor.defaultFormatter": "esbenp.prettier-vscode"
58+
},
59+
"extensions": {
60+
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
61+
}
6262
}

packages/lit-html/src/lit-html.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,14 @@ const debugLogEvent = DEV_MODE
192192
? (event: LitUnstable.DebugLog.Entry) => {
193193
const shouldEmit = (window as unknown as DebugLoggingWindow)
194194
.emitLitDebugLogEvents;
195-
if (shouldEmit) {
196-
window.dispatchEvent(
197-
new CustomEvent<LitUnstable.DebugLog.Entry>('lit-debug', {
198-
detail: event,
199-
})
200-
);
195+
if (!shouldEmit) {
196+
return;
201197
}
198+
window.dispatchEvent(
199+
new CustomEvent<LitUnstable.DebugLog.Entry>('lit-debug', {
200+
detail: event,
201+
})
202+
);
202203
}
203204
: undefined;
204205
// Used for connecting beginRender and endRender events when there are nested
@@ -1480,7 +1481,7 @@ class ChildPart implements Disconnectable {
14801481
kind: 'commit node',
14811482
start: this._$startNode,
14821483
parent: this._$parent,
1483-
value: value.cloneNode(true),
1484+
value: value,
14841485
options: this.options,
14851486
});
14861487
this._$committedValue = this._insert(value);

packages/reactive-element/src/reactive-element.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,14 @@ const debugLogEvent = DEV_MODE
141141
? (event: ReactiveUnstable.DebugLog.Entry) => {
142142
const shouldEmit = (window as unknown as DebugLoggingWindow)
143143
.emitLitDebugLogEvents;
144-
if (shouldEmit) {
145-
window.dispatchEvent(
146-
new CustomEvent<ReactiveUnstable.DebugLog.Entry>('lit-debug', {
147-
detail: event,
148-
})
149-
);
144+
if (!shouldEmit) {
145+
return;
150146
}
147+
window.dispatchEvent(
148+
new CustomEvent<ReactiveUnstable.DebugLog.Entry>('lit-debug', {
149+
detail: event,
150+
})
151+
);
151152
}
152153
: undefined;
153154

0 commit comments

Comments
 (0)