Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5d340f1
Revert change to pause update cycle while disconnected
kevinpschaaf Aug 4, 2021
422478e
Move directive changes to follow-on PR
kevinpschaaf Aug 10, 2021
9682937
Add changeset
kevinpschaaf Aug 10, 2021
2926046
Make copy of user options since we're modifying it
kevinpschaaf Aug 10, 2021
114d1d4
Only copy options once when making part
kevinpschaaf Aug 10, 2021
fa3b1ea
Update packages/lit-html/src/test/lit-html_test.ts
kevinpschaaf Aug 10, 2021
d313272
Get isConnected from parent via getter vs. options
kevinpschaaf Aug 10, 2021
20fb5d7
Fixes for SSR
kevinpschaaf Aug 10, 2021
6f53e2e
Fix typo
kevinpschaaf Aug 11, 2021
4ed25b3
Add test for updates when disconnected
kevinpschaaf Aug 11, 2021
327f45b
Fix LitElement test
kevinpschaaf Aug 11, 2021
4d650dc
Fix SSR build
kevinpschaaf Aug 11, 2021
453e6c2
Remove unused __enableConnection
kevinpschaaf Aug 11, 2021
553a1eb
Refactor logic
kevinpschaaf Aug 11, 2021
0f385eb
Remove unneeded assertion
kevinpschaaf Aug 11, 2021
be97018
Avoid subclass for RootChildPart for perf
kevinpschaaf Aug 13, 2021
94c118a
Add test for insertPart keeping connection state in sync
kevinpschaaf Aug 13, 2021
7a4c9eb
Add TODO & test for initially disconnected LitElement
kevinpschaaf Aug 13, 2021
3f1a352
Add issue link
kevinpschaaf Aug 13, 2021
3409fd3
Use local isConnected state in AsyncDirective for perf
kevinpschaaf Aug 13, 2021
e2255d8
Add comment
kevinpschaaf Aug 13, 2021
6737e16
Remove unused file and add comment
kevinpschaaf Aug 13, 2021
bcfba1d
Ensure _$litStatic$ is stable
kevinpschaaf Aug 16, 2021
a54c3dc
Add jsdocs, rename RootChildPart -> RootPart
kevinpschaaf Aug 17, 2021
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
7 changes: 7 additions & 0 deletions .changeset/curvy-olives-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@lit-labs/ssr': patch
'lit-html': patch
'@lit/reactive-element': patch
---

Reverts the change in Lit 2 to pause ReactiveElement's update cycle while the element is disconnected. The update cycle for elements will now run while disconnected as in Lit 1, however AsyncDirectives must now check the `this.isConnected` flag during `update` to ensure that e.g. subscriptions that could lead to memory leaks are not made when AsyncDirectives update while disconnected.
2 changes: 1 addition & 1 deletion .vscode/terminals.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"name": "TS: ssr",
"icon": "checklist",
"cwd": "[workspaceFolder]/packages/labs/ssr",
"command": "npm run build:watch",
"command": "npm run build:ts:watch",
"focus": true
},
{
Expand Down
21 changes: 0 additions & 21 deletions packages/benchmarks/lit-element/list/tachometer-render.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,6 @@
}
}
}
},
{
"name": "previous-release",
"packageVersions": {
"label": "previous-release",
"dependencies": {
"lit-html": "^1.0.0",
"lit-element": "^2.0.0",
"@lit/reactive-element": {
"kind": "git",
"repo": "https://github.com/lit/lit-html.git",
"ref": "main",
"subdir": "packages/reactive-element",
"setupCommands": [
"npm ci",
"npm run bootstrap -- --concurrency=1",
"npm run build"
]
}
}
}
}
]
}
Expand Down
15 changes: 10 additions & 5 deletions packages/labs/ssr/src/lib/render-lit-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {

import {nothing, noChange} from 'lit';
import {PartType} from 'lit/directive.js';
import {isTemplateResult} from 'lit/directive-helpers.js';
import {isTemplateResult, getDirectiveClass} from 'lit/directive-helpers.js';
import {_$LH} from 'lit-html/private-ssr-support.js';

const {
Expand All @@ -24,12 +24,14 @@ const {
markerMatch,
boundAttributeSuffix,
overrideDirectiveResolve,
setDirectiveClass,
getAttributePartCommittedValue,
resolveDirective,
AttributePart,
PropertyPart,
BooleanAttributePart,
EventPart,
connectedDisconnectable,
} = _$LH;

import {digestForTemplateResult} from 'lit/experimental-hydrate.js';
Expand Down Expand Up @@ -75,7 +77,7 @@ const patchedDirectiveCache: WeakMap<DirectiveClass, DirectiveClass> =
*/
const patchIfDirective = (value: unknown) => {
// This property needs to remain unminified.
const directiveCtor = (value as DirectiveResult)?.['_$litDirective$'];
const directiveCtor = getDirectiveClass(value);
if (directiveCtor !== undefined) {
let patchedCtor = patchedDirectiveCache.get(directiveCtor);
if (patchedCtor === undefined) {
Expand All @@ -90,7 +92,7 @@ const patchIfDirective = (value: unknown) => {
patchedDirectiveCache.set(directiveCtor, patchedCtor);
}
// This property needs to remain unminified.
(value as DirectiveResult)['_$litDirective$'] = patchedCtor;
setDirectiveClass(value as DirectiveResult, patchedCtor);
}
return value;
};
Expand Down Expand Up @@ -556,7 +558,10 @@ function* renderValue(
}
value = null;
} else {
value = resolveDirective({type: PartType.CHILD} as ChildPart, value);
value = resolveDirective(
connectedDisconnectable({type: PartType.CHILD}) as ChildPart,
value
);
}
if (value != null && isTemplateResult(value)) {
yield `<!--lit-part ${digestForTemplateResult(value as TemplateResult)}-->`;
Expand Down Expand Up @@ -624,7 +629,7 @@ function* renderTemplateResult(
{tagName: op.tagName} as HTMLElement,
op.name,
statics,
undefined,
connectedDisconnectable(),
{}
);
const value =
Expand Down
4 changes: 2 additions & 2 deletions packages/lit-element/src/lit-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @packageDocumentation
*/
import {PropertyValues, ReactiveElement} from '@lit/reactive-element';
import {render, RenderOptions, noChange, ChildPart} from 'lit-html';
import {render, RenderOptions, noChange, RootChildPart} from 'lit-html';
export * from '@lit/reactive-element';
export * from 'lit-html';

Expand Down Expand Up @@ -95,7 +95,7 @@ export class LitElement extends ReactiveElement {
*/
readonly renderOptions: RenderOptions = {host: this};

private __childPart: ChildPart | undefined = undefined;
private __childPart: RootChildPart | undefined = undefined;

/**
* @category rendering
Expand Down
54 changes: 35 additions & 19 deletions packages/lit-element/src/test/lit-element_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ const extraGlobals = window as LitExtraGlobals;
class extends AsyncDirective {
id!: unknown;
render(id: unknown) {
log.push(`render-${id}`);
log.push(`render-${id}-${this.isConnected}`);
return (this.id = id);
}
disconnected() {
Expand All @@ -373,7 +373,7 @@ const extraGlobals = window as LitExtraGlobals;
}
get child() {
// Cast to child so we can access .prop off of the div
return this.shadowRoot!.firstElementChild as Child;
return this.shadowRoot?.firstElementChild;
}
}
customElements.define('disc-child', Child);
Expand All @@ -392,14 +392,16 @@ const extraGlobals = window as LitExtraGlobals;
customElements.define('disc-host', Host);

const assertRendering = (host: Host) => {
let child = host.child;
const child = host.child;
assert.equal(child.getAttribute('attr'), 'host-attr');
assert.equal(child.prop, 'host-prop');
assert.equal(child.textContent?.trim(), 'host-node');
child = child.child;
assert.equal(child.getAttribute('attr'), 'child-attr');
assert.equal(child.prop, 'child-prop');
assert.equal(child.textContent?.trim(), 'child-node');
const grandChild = child.child as Child;
if (grandChild) {
assert.equal(grandChild.getAttribute('attr'), 'child-attr');
assert.equal(grandChild.prop, 'child-prop');
assert.equal(grandChild.textContent?.trim(), 'child-node');
}
};

setup(() => {
Expand All @@ -418,12 +420,12 @@ const extraGlobals = window as LitExtraGlobals;
await nextFrame();
assertRendering(host);
assert.deepEqual(log, [
'render-host-attr',
'render-host-prop',
'render-host-node',
'render-child-attr',
'render-child-prop',
'render-child-node',
'render-host-attr-true',
'render-host-prop-true',
'render-host-node-true',
'render-child-attr-true',
'render-child-prop-true',
'render-child-node-true',
]);
});

Expand Down Expand Up @@ -506,12 +508,26 @@ const extraGlobals = window as LitExtraGlobals;
await nextFrame();
assertRendering(host);
assert.deepEqual(log, [
'render-host-attr',
'render-host-prop',
'render-host-node',
'render-child-attr',
'render-child-prop',
'render-child-node',
'render-host-attr-true',
'render-host-prop-true',
'render-host-node-true',
'render-child-attr-true',
'render-child-prop-true',
'render-child-node-true',
]);
});

// TODO(kschaaf): render does not currently support rendering to an
// initially disconnected ChildPart (https://github.com/lit/lit/issues/2051)
test.skip('directives render with isConnected: false if first render is while element is disconnected', async () => {
container.appendChild(host);
container.remove();
await nextFrame();
assertRendering(host);
assert.deepEqual(log, [
'render-host-attr-false',
'render-host-prop-false',
'render-host-node-false',
]);
});
});
Expand Down
Loading