summaryrefslogtreecommitdiff
path: root/packages/integrations/lit/server.js
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2024-08-19 08:12:33 -0400
committerGravatar GitHub <noreply@github.com> 2024-08-19 08:12:33 -0400
commit3822e574aa1d779020983a2d9815b3974a9d911a (patch)
treee73bc12683498256f3a27c3d57033427f0eff71a /packages/integrations/lit/server.js
parent7ffcae19064a8c912a7d5e8c943952923d20edc5 (diff)
downloadastro-3822e574aa1d779020983a2d9815b3974a9d911a.tar.gz
astro-3822e574aa1d779020983a2d9815b3974a9d911a.tar.zst
astro-3822e574aa1d779020983a2d9815b3974a9d911a.zip
Remove @astrojs/lit (#11680)
* Remove @astrojs/lit This removes the Lit integration as an official integration. The reasons for doing so in 5.0: - Only 1% of Astro users use this integration. - SSR support in Lit is at a lower-level of support due to be a Labs project: https://lit.dev/docs/libraries/labs/, and has been in this state since we added support a couple of years ago. - The maintenance cost of fixing bugs in this integration is too high given the low usage. Some PRs for upgrading Lit versions have taken quite a long time. We can't justify the core team being responsible for this going forward. - There used to be community contributions to fix bugs but this has fallen off for various reasons. Given that, this PR removes the integration as one that is officially supported by the Astro core team. Interested community members are encouraged to fork the integration and continue the development in another repository. * Remove e2e tests and examples * Update lockfile * Remove ssr-lit.test.js * Remove error for no client entrypoint * Remove auto selection of the Lit renderer * Remove lit package.json * Remove lit fixture
Diffstat (limited to 'packages/integrations/lit/server.js')
-rw-r--r--packages/integrations/lit/server.js118
1 files changed, 0 insertions, 118 deletions
diff --git a/packages/integrations/lit/server.js b/packages/integrations/lit/server.js
deleted file mode 100644
index d1da3c6c9..000000000
--- a/packages/integrations/lit/server.js
+++ /dev/null
@@ -1,118 +0,0 @@
-// Separate import from the rest so it doesn't get re-organized after other imports
-import './server-shim.js';
-
-import { LitElementRenderer } from '@lit-labs/ssr/lib/lit-element-renderer.js';
-import * as parse5 from 'parse5';
-
-function isCustomElementTag(name) {
- return typeof name === 'string' && name.includes('-');
-}
-
-function getCustomElementConstructor(name) {
- if (typeof customElements !== 'undefined' && isCustomElementTag(name)) {
- return customElements.get(name) || null;
- } else if (typeof name === 'function') {
- return name;
- }
- return null;
-}
-
-async function isLitElement(Component) {
- const Ctr = getCustomElementConstructor(Component);
- return !!Ctr?._$litElement$;
-}
-
-async function check(Component) {
- // Lit doesn't support getting a tagName from a Constructor at this time.
- // So this must be a string at the moment.
- return !!(await isLitElement(Component));
-}
-
-function* render(Component, attrs, slots) {
- let tagName = Component;
- if (typeof tagName !== 'string') {
- tagName = Component[Symbol.for('tagName')];
- }
- const instance = new LitElementRenderer(tagName);
-
- // LitElementRenderer creates a new element instance, so copy over.
- const Ctr = getCustomElementConstructor(tagName);
- let shouldDeferHydration = false;
-
- if (attrs) {
- for (let [name, value] of Object.entries(attrs)) {
- const isReactiveProperty = name in Ctr.prototype;
- const isReflectedReactiveProperty = Ctr.elementProperties.get(name)?.reflect;
-
- // Only defer hydration if we are setting a reactive property that cannot
- // be reflected / serialized as a property.
- shouldDeferHydration ||= isReactiveProperty && !isReflectedReactiveProperty;
-
- if (isReactiveProperty) {
- instance.setProperty(name, value);
- } else {
- instance.setAttribute(name, value);
- }
- }
- }
-
- instance.connectedCallback();
-
- yield `<${tagName}${shouldDeferHydration ? ' defer-hydration' : ''}`;
- yield* instance.renderAttributes();
- yield `>`;
- const shadowContents = instance.renderShadow({
- elementRenderers: [LitElementRenderer],
- customElementInstanceStack: [instance],
- customElementHostStack: [instance],
- deferHydration: false,
- });
- if (shadowContents !== undefined) {
- const { mode = 'open', delegatesFocus } = instance.shadowRootOptions ?? {};
- // `delegatesFocus` is intentionally allowed to coerce to boolean to
- // match web platform behavior.
- const delegatesfocusAttr = delegatesFocus ? ' shadowrootdelegatesfocus' : '';
- yield `<template shadowroot="${mode}" shadowrootmode="${mode}"${delegatesfocusAttr}>`;
- yield* shadowContents;
- yield '</template>';
- }
- if (slots) {
- for (let [slot, value = ''] of Object.entries(slots)) {
- if (slot !== 'default' && value) {
- // Parse the value as a concatenated string
- const fragment = parse5.parseFragment(`${value}`);
-
- // Add the missing slot attribute to child Element nodes
- for (const node of fragment.childNodes) {
- if (node.tagName && !node.attrs.some(({ name }) => name === 'slot')) {
- node.attrs.push({ name: 'slot', value: slot });
- }
- }
-
- value = parse5.serialize(fragment);
- }
-
- yield value;
- }
- }
- yield `</${tagName}>`;
-}
-
-async function renderToStaticMarkup(Component, props, slots) {
- let tagName = Component;
-
- let out = '';
- for (let chunk of render(tagName, props, slots)) {
- out += chunk;
- }
-
- return {
- html: out,
- };
-}
-
-export default {
- name: '@astrojs/lit',
- check,
- renderToStaticMarkup,
-};