-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lit-ssr] Initial commit of lit-ssr package (#1347)
* Initial SSR commit (code copied from #hydration & lit-ssr) * Initial lit-html rendering/hydration (element tests disabled) * Add LitElement support (no renderLight yet) Fix lit-element import paths For now, build template-shadowroot as part of lit-ssr Add lit-ssr tests to CI Fix merge error (Template:_options) Remove tsconfig.tsbuildinfo Uncomment element tests ffrom server-only suite Fix return value of createRenderRoot patch * Add private-ssr-support to lit-html for re-exporting private symbols * Cleanup & update README Rename $litPrivate -> $private Fix demo hydration README updates * Add renderLight directive * Disable incremental compilation for now * Update ssr code to new lint rules Some minor cleanup included * Format all and fix formatting errors * Remove format script from lit-ssr package.json Co-authored-by: Abdón Rodríguez Davila <[email protected]> * Cleanup package.json * Add a strawman for files to publish * Add test from PolymerLabs/lit-ssr#63 * Remove `only` from test * Add pacakge to README * Add hydrate-support.js to exports * Add TODOs for async directives * Update comment to avoid it being specific to LitElement * Remove seemingly unnecessary export * Add comments * Review feedback Rename Directive:resolve -> _resolve Add comments * Make _start/_endNode @internal * Remove prettier config from package * Fix code sample to match text * Remove dirty-check; use elementStyles * Add todo/issue for reflecting attributes * Add 'koa-' prefix to middleware module name * Fix comment, remove duplication. * Cleanup * Address more review feedback * Switch to escape-html * Patch update instead of render Return `noChage` from default render now that we don't clear the container before rendering, which was the reason for renderNotImplemented. * Address more review feedback * Remove middleware, move to new PR * Add test for directive in EventPart * Address review feedback * Add licenses * Add a little more to dom-shim to remove client checks * Return an array from getTemplateHtml for terseness * Revert _resolveValue factoring (had perf impact); use optional commitValue override * Downgrade Chrome for time being * Try the other direction with Chrome * Switch to using a boolean for overriding commit, and patch _commitValue during SSR * Revise comment Co-authored-by: Abdón Rodríguez Davila <[email protected]>
- Loading branch information
1 parent
0cf140e
commit dcd088f
Showing
52 changed files
with
15,038 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"autorun": false, | ||
"terminals": [ | ||
{ | ||
"name": "TS: lit-html", | ||
"icon": "checklist", | ||
"cwd": "[workspaceFolder]/packages/lit-html", | ||
"command": "npm run build:ts:watch" | ||
}, | ||
{ | ||
"name": "TS: updating-element", | ||
"icon": "checklist", | ||
"cwd": "[workspaceFolder]/packages/updating-element", | ||
"command": "npm run build:ts:watch" | ||
}, | ||
{ | ||
"name": "TS: lit-element", | ||
"icon": "checklist", | ||
"cwd": "[workspaceFolder]/packages/lit-element", | ||
"command": "npm run build:ts:watch" | ||
}, | ||
{ | ||
"name": "TS: lit-ssr", | ||
"icon": "checklist", | ||
"cwd": "[workspaceFolder]/packages/lit-ssr", | ||
"command": "npm run build:watch", | ||
"focus": true | ||
}, | ||
{ | ||
"name": "Rollup: lit-html", | ||
"icon": "checklist", | ||
"cwd": "[workspaceFolder]/packages/lit-html", | ||
"command": "npm run build:watch" | ||
}, | ||
{ | ||
"name": "Rollup: updating-element", | ||
"icon": "checklist", | ||
"cwd": "[workspaceFolder]/packages/updating-element", | ||
"command": "npm run build:watch" | ||
}, | ||
{ | ||
"name": "Rollup: lit-element", | ||
"icon": "checklist", | ||
"cwd": "[workspaceFolder]/packages/lit-element", | ||
"command": "npm run build:watch" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,36 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"name": "lit-html", | ||
"path": "packages/lit-html" | ||
}, | ||
{ | ||
"name": "lit-element", | ||
"path": "packages/lit-element" | ||
}, | ||
{ | ||
"name": "updating-element", | ||
"path": "packages/updating-element" | ||
}, | ||
{ | ||
"name": "tests", | ||
"path": "packages/tests" | ||
}, | ||
{ | ||
"name": "benchmarks", | ||
"path": "packages/benchmarks" | ||
}, | ||
{ | ||
"name": "lit-next", | ||
"path": "." | ||
} | ||
], | ||
"settings": { | ||
"typescript.tsdk": "lit-html/node_modules/typescript/lib" | ||
} | ||
"folders": [ | ||
{ | ||
"name": "lit-html", | ||
"path": "packages/lit-html" | ||
}, | ||
{ | ||
"name": "lit-element", | ||
"path": "packages/lit-element" | ||
}, | ||
{ | ||
"name": "updating-element", | ||
"path": "packages/updating-element" | ||
}, | ||
{ | ||
"name": "lit-ssr", | ||
"path": "packages/lit-ssr" | ||
}, | ||
{ | ||
"name": "tests", | ||
"path": "packages/tests" | ||
}, | ||
{ | ||
"name": "benchmarks", | ||
"path": "packages/benchmarks" | ||
}, | ||
{ | ||
"name": "lit-next", | ||
"path": "." | ||
} | ||
], | ||
"settings": { | ||
"typescript.tsdk": "lit-html/node_modules/typescript/lib", | ||
"debug.javascript.warnOnLongPrediction": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved. | ||
* This code may only be used under the BSD style license found at | ||
* http://polymer.github.io/LICENSE.txt | ||
* The complete set of authors may be found at | ||
* http://polymer.github.io/AUTHORS.txt | ||
* The complete set of contributors may be found at | ||
* http://polymer.github.io/CONTRIBUTORS.txt | ||
* Code distributed by Google as part of the polymer project is also | ||
* subject to an additional IP rights grant found at | ||
* http://polymer.github.io/PATENTS.txt | ||
*/ | ||
|
||
/** | ||
* LitElement support for hydration of content rendered using lit-ssr. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
import {PropertyValues, UpdatingElement} from 'updating-element'; | ||
import {render} from 'lit-html'; | ||
import {hydrate} from 'lit-html/hydrate.js'; | ||
|
||
interface PatchableLitElement extends HTMLElement { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-misused-new | ||
new (...args: any[]): PatchableLitElement; | ||
createRenderRoot(): Element | ShadowRoot; | ||
_needsHydration: boolean; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(globalThis as any)['litElementHydrateSupport'] = ({ | ||
LitElement, | ||
}: { | ||
LitElement: PatchableLitElement; | ||
}) => { | ||
// Capture whether we need hydration or not | ||
const createRenderRoot = LitElement.prototype.createRenderRoot; | ||
LitElement.prototype.createRenderRoot = function () { | ||
if (this.shadowRoot) { | ||
this._needsHydration = true; | ||
return this.shadowRoot; | ||
} else { | ||
return createRenderRoot.call(this); | ||
} | ||
}; | ||
|
||
// Hydrate on first update when needed | ||
LitElement.prototype.update = function (changedProperties: PropertyValues) { | ||
const value = this.render(); | ||
// Since this is a patch, we can't call super.update() | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
(UpdatingElement.prototype as any).update.call(this, changedProperties); | ||
if (this._needsHydration) { | ||
this._needsHydration = false; | ||
hydrate(value, this.renderRoot, this._renderOptions); | ||
} else { | ||
render(value, this.renderRoot, this._renderOptions); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.