@context-action/lit-ui 0.0.0-stage → 0.1.1
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/CHANGELOG.md +64 -0
- package/LICENSE +201 -0
- package/README.md +117 -2
- package/dist/hydrate.cjs +218 -0
- package/dist/hydrate.cjs.map +1 -0
- package/dist/hydrate.d.cts +18 -0
- package/dist/hydrate.d.cts.map +1 -0
- package/dist/hydrate.d.ts +18 -0
- package/dist/hydrate.d.ts.map +1 -0
- package/dist/hydrate.js +206 -0
- package/dist/hydrate.js.map +1 -0
- package/dist/index.cjs +1636 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +644 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +644 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1571 -0
- package/dist/index.js.map +1 -0
- package/dist/ssr.cjs +116 -0
- package/dist/ssr.cjs.map +1 -0
- package/dist/ssr.d.cts +53 -0
- package/dist/ssr.d.cts.map +1 -0
- package/dist/ssr.d.ts +53 -0
- package/dist/ssr.d.ts.map +1 -0
- package/dist/ssr.js +111 -0
- package/dist/ssr.js.map +1 -0
- package/docs/01-dom-ownership.md +133 -0
- package/docs/02-reactive-controller-vs-hooks.md +246 -0
- package/docs/03-form-associated-elements.md +585 -0
- package/docs/04-micro-frontend-communication.md +682 -0
- package/docs/05-interface-and-state-management-standards.md +210 -0
- package/docs/06-ssr-hydration.md +161 -0
- package/docs/07-release-and-verification.md +168 -0
- package/package.json +105 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
## [0.1.1] (2026-10-23)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- `hydrateLit(host.shadowRoot, host)` now finds `lit-part` markers anywhere
|
|
8
|
+
under the shadow root instead of assuming they are direct siblings of the
|
|
9
|
+
first node. Declarative shadow roots with `static styles` are adopted instead
|
|
10
|
+
of appending a second client render.
|
|
11
|
+
- If a client render already appended a duplicate tree before `hydrateLit` runs,
|
|
12
|
+
the server root part is isolated, the client tree is removed, and the server
|
|
13
|
+
tree is re-adopted. Final item counts and server node identity are preserved.
|
|
14
|
+
|
|
15
|
+
### Tests
|
|
16
|
+
|
|
17
|
+
- Added static-styles + three-item DSD hydration regression coverage in jsdom
|
|
18
|
+
and Chromium, including the late `hydrateLit` after first-update scenario.
|
|
19
|
+
|
|
20
|
+
## [0.1.0] (2026-10-23)
|
|
21
|
+
|
|
22
|
+
Published to npm on 2026-10-23. `latest` and `next` resolve to `0.1.0`.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- Initial public release of the Lit UI primitives and integrations.
|
|
27
|
+
- `FormAssociatedLitElement` with ElementInternals, constraint validation,
|
|
28
|
+
form value management, and reset/state-restore lifecycle hooks.
|
|
29
|
+
- W3C `@lit/context` tokens, providers, and controllers for stores and action
|
|
30
|
+
registers across Shadow DOM boundaries.
|
|
31
|
+
- `createLitElementBridge` for React 18/19 with direct complex-property
|
|
32
|
+
assignment, bridge-owned property removal, handler-identity event
|
|
33
|
+
reconciliation, StrictMode safety, attribute passthrough, and OOP facade
|
|
34
|
+
handles through `createHandle` / `createElementFacade`.
|
|
35
|
+
- `@context-action/lit-ui/ssr` with `renderLitElement`, `renderLitTemplate`,
|
|
36
|
+
reflected host attributes, light DOM/slot preservation, and async renderer
|
|
37
|
+
variants.
|
|
38
|
+
- `@context-action/lit-ui/hydrate` as a client-only entry with Lit hydration
|
|
39
|
+
support, declarative shadow root adoption, template hydration, and no server
|
|
40
|
+
renderer dependency.
|
|
41
|
+
- Reference `LitQuantityStepper` and `LitCartBadge` custom elements.
|
|
42
|
+
- `ControllerScope` re-export from `@context-action/lit`.
|
|
43
|
+
|
|
44
|
+
### Verification
|
|
45
|
+
|
|
46
|
+
- Unit, stress, React 18 consumer matrix, processless/Edge runtime, and Chromium
|
|
47
|
+
declarative-shadow-DOM hydration contracts run through `pnpm check:lit`,
|
|
48
|
+
`pnpm verify:lit-react-compatibility`, and `pnpm --filter @context-action/lit-ui test:browser`.
|
|
49
|
+
- Package exports and tarballs are part of the public package verification,
|
|
50
|
+
including a packed consumer install smoke.
|
|
51
|
+
|
|
52
|
+
### Changed
|
|
53
|
+
|
|
54
|
+
- Tooling updated to React 19.3.1 for the development matrix, Vitest `5.0.5`,
|
|
55
|
+
jsdom `30.1.3`, Vite `8.3.5`, and tsdown `0.23.1`; TypeScript remains on the
|
|
56
|
+
repository's `6.0.3` baseline.
|
|
57
|
+
- Reference custom elements use idempotent registration so ESM and CJS builds
|
|
58
|
+
can be loaded in the same process without a duplicate-definition error.
|
|
59
|
+
|
|
60
|
+
### Documentation
|
|
61
|
+
|
|
62
|
+
- README and `docs/` cover DOM ownership, ReactiveController architecture, FACE,
|
|
63
|
+
W3C context communication, interface standards, SSR, hydration, and the React
|
|
64
|
+
bridge contract.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 Jun Woo Bang
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,118 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @context-action/lit-ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Web Component primitives, Form-Associated Custom Elements (FACE), W3C Context Protocol (`@lit/context`) dependency injection, and React 18/19 custom element bridge for the Context-Action state management framework.
|
|
4
|
+
|
|
5
|
+
## Responsibilities
|
|
6
|
+
|
|
7
|
+
- **`FormAssociatedLitElement`**: Abstract base class extending `LitElement` with full Form-Associated Custom Elements (FACE) support (`ElementInternals`, standard validation constraints, `setFormValue()`, and leak-free `formResetCallback()` coordination).
|
|
8
|
+
- **W3C Context Protocol Integration**: Global context tokens (`actionRegisterContext`, `actionDispatcherContext`, `createStoreContext`), imperative providers (`provideStore`, `provideActionRegister`, `provideActionDispatcher`), and reactive context controllers (`ContextStoreController`, `ContextActionController`) crossing Shadow DOM boundaries.
|
|
9
|
+
- **`createLitElementBridge`**: React 18/19 custom element bridge with direct property assignment (bypassing attribute stringification), property removal, handler-identity event reconciliation, OOP facade handles, and ref forwarding.
|
|
10
|
+
- **`@context-action/lit-ui/ssr`**: Lit SSR renderers (`renderLitElement`, `renderLitTemplate`) and client hydration (`hydrateLit`) that preserve `part`, `data-*`, and declarative shadow roots.
|
|
11
|
+
- **`@context-action/lit-ui/hydrate`**: Client-only hydration entry. It loads Lit hydration support and never imports the server renderer.
|
|
12
|
+
- **`ControllerScope`**: Re-exported from `@context-action/lit` for LIFO ReactiveController and cleanup disposal.
|
|
13
|
+
|
|
14
|
+
## React Bridge
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { createElementFacade, createLitElementBridge } from '@context-action/lit-ui';
|
|
18
|
+
|
|
19
|
+
type TimelineHandle = Pick<TimelineElement, 'focusItem' | 'scrollTo' | 'commitSelection'>;
|
|
20
|
+
|
|
21
|
+
const ReactTimeline = createLitElementBridge<TimelineProps, TimelineElement, TimelineHandle>({
|
|
22
|
+
tagName: 'st-timeline',
|
|
23
|
+
properties: ['input', 'set'],
|
|
24
|
+
events: { onSelectionChange: 'selection-change' },
|
|
25
|
+
createHandle: createElementFacade<
|
|
26
|
+
TimelineElement,
|
|
27
|
+
readonly ['focusItem', 'scrollTo', 'commitSelection']
|
|
28
|
+
>(['focusItem', 'scrollTo', 'commitSelection']),
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- Properties removed from props are reset to `undefined`; read-only properties keep their adapter-owned value.
|
|
33
|
+
- Event listeners are reconciled by handler identity, so a re-render with the same handler performs zero `addEventListener` calls.
|
|
34
|
+
- `createHandle` exposes only the declared facade methods; raw element internals stay private.
|
|
35
|
+
- Props not listed in `properties`/`events` continue to render as DOM attributes.
|
|
36
|
+
|
|
37
|
+
## SSR and hydration
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
// Server (Node/Edge/Worker)
|
|
41
|
+
import { renderLitElement, renderLitTemplate } from '@context-action/lit-ui/ssr';
|
|
42
|
+
|
|
43
|
+
const markup = renderLitElement(timelineElement);
|
|
44
|
+
// or: const markup = renderLitTemplate(html`<st-timeline></st-timeline>`);
|
|
45
|
+
|
|
46
|
+
// Client — import before defining Lit elements so hydration support is installed.
|
|
47
|
+
import { hydrateLit } from '@context-action/lit-ui/hydrate';
|
|
48
|
+
|
|
49
|
+
hydrateLit(container, timelineElement);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The `./ssr` entry requires `@lit-labs/ssr` and `@lit-labs/ssr-client` (optional peers; install them in server/catalog deployments).
|
|
53
|
+
`renderLitElement` requires the element to be registered with `customElements.define()` first.
|
|
54
|
+
Reflected reactive properties are serialized as host attributes, and light DOM children are included by default so `<slot>` projection survives SSR (`includeLightDom: false` opts out).
|
|
55
|
+
`hydrateLit` re-exports from `./ssr` for compatibility, but `./hydrate` keeps the server renderer out of client bundles.
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pnpm add @context-action/lit-ui @context-action/lit lit @lit/context
|
|
61
|
+
# Optional: SSR/catalog deployments
|
|
62
|
+
pnpm add @lit-labs/ssr @lit-labs/ssr-client
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`lit`, `@lit/context`, and `react` are peer dependencies. `react` is optional
|
|
66
|
+
and only needed for `createLitElementBridge`. The SSR peers are optional and
|
|
67
|
+
only needed for `@context-action/lit-ui/ssr`.
|
|
68
|
+
|
|
69
|
+
The SSR entry does not read `window` or `document` at module evaluation time,
|
|
70
|
+
and builds to both ESM and CJS.
|
|
71
|
+
`renderLitTemplateAsync` / `renderLitElementAsync` are available for asynchronous element renderers.
|
|
72
|
+
|
|
73
|
+
## Verification
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pnpm check:lit # build + type-check + unit + edge runtime
|
|
77
|
+
pnpm verify:lit-react-compatibility # React 18 consumer matrix
|
|
78
|
+
pnpm --filter @context-action/lit-ui test:browser # Chromium DSD hydration contract
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Status
|
|
82
|
+
|
|
83
|
+
Public package. `0.1.1` is the current patch release candidate for the
|
|
84
|
+
static-styles hydration fix; `0.1.0` remains the last published version until
|
|
85
|
+
the candidate/promotion workflows complete.
|
|
86
|
+
|
|
87
|
+
- https://www.npmjs.com/package/@context-action/lit-ui
|
|
88
|
+
- Release plan: [`releases/LIT_PUBLIC_0.1.1.md`](../../releases/LIT_PUBLIC_0.1.1.md)
|
|
89
|
+
|
|
90
|
+
Requires Node.js `>=24.11.0`.
|
|
91
|
+
|
|
92
|
+
## Architecture
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
┌────────────────────────────────────────────────────────┐
|
|
96
|
+
│ React 18/19 Host Application │
|
|
97
|
+
│ └── createLitElementBridge(CustomElement) │
|
|
98
|
+
└───────────────────────────┬────────────────────────────┘
|
|
99
|
+
│ (Direct Properties & Custom Events)
|
|
100
|
+
┌───────────────────────────▼────────────────────────────┐
|
|
101
|
+
│ Custom Element (LitElement / FormAssociatedLitElement) │
|
|
102
|
+
│ ├── #shadow-root (Encapsulated CSS & DOM) │
|
|
103
|
+
│ ├── ElementInternals (Native Form Participation) │
|
|
104
|
+
│ ├── ContextStoreController / ContextActionController │
|
|
105
|
+
│ │ ▲ │
|
|
106
|
+
│ │ │ (W3C Context Protocol: context-request) │
|
|
107
|
+
│ └─────┴──────────────────────────────────────────────┘
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Documentation
|
|
111
|
+
|
|
112
|
+
- [01. DOM Ownership & Shadow DOM Isolation](docs/01-dom-ownership.md)
|
|
113
|
+
- [02. ReactiveController vs React Hooks & 3-Layer Architecture](docs/02-reactive-controller-vs-hooks.md)
|
|
114
|
+
- [03. Form-Associated Custom Elements (FACE) & ElementInternals](docs/03-form-associated-elements.md)
|
|
115
|
+
- [04. W3C Context Protocol & Micro-Frontend Communication](docs/04-micro-frontend-communication.md)
|
|
116
|
+
- [05. Interface Design & Baseline State Management Standards](docs/05-interface-and-state-management-standards.md)
|
|
117
|
+
- [06. SSR and Hydration Entry](docs/06-ssr-hydration.md)
|
|
118
|
+
- [07. Public Release and Verification](docs/07-release-and-verification.md)
|
package/dist/hydrate.cjs
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let lit = require("lit");
|
|
3
|
+
require("@lit-labs/ssr-client/lit-element-hydrate-support.js");
|
|
4
|
+
let _lit_labs_ssr_client = require("@lit-labs/ssr-client");
|
|
5
|
+
// src/hydrate.ts
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview Client-only hydration entry (`@context-action/lit-ui/hydrate`).
|
|
8
|
+
*
|
|
9
|
+
* This module intentionally imports only `@lit-labs/ssr-client` and the Lit
|
|
10
|
+
* runtime, never the server renderer. Client bundles that only need
|
|
11
|
+
* `hydrateLit()` can avoid pulling `@lit-labs/ssr` into the browser graph.
|
|
12
|
+
*
|
|
13
|
+
* @implements view-layer
|
|
14
|
+
* @implements web-component-primitive
|
|
15
|
+
* @memberof core-concepts
|
|
16
|
+
*/
|
|
17
|
+
const COMMENT_NODE = 8;
|
|
18
|
+
const DOCUMENT_FRAGMENT_NODE = 11;
|
|
19
|
+
function hasLitPartMarker(root) {
|
|
20
|
+
const document = root.ownerDocument ?? root.host?.ownerDocument ?? null;
|
|
21
|
+
if (document && typeof document.createTreeWalker === "function") {
|
|
22
|
+
const walker = document.createTreeWalker(root, 128);
|
|
23
|
+
while (walker.nextNode()) if (walker.currentNode.data.startsWith("lit-part")) return true;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
for (let node = root.firstChild; node; node = node.nextSibling) {
|
|
27
|
+
if (node.nodeType === COMMENT_NODE && node.data.startsWith("lit-part")) return true;
|
|
28
|
+
if (node.nodeType === 1 && hasLitPartMarker(node)) return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
function findServerHost(root, element) {
|
|
33
|
+
const tagName = element.localName;
|
|
34
|
+
if (!tagName) return null;
|
|
35
|
+
if (root.nodeType === DOCUMENT_FRAGMENT_NODE && "host" in root && root.host === element) return null;
|
|
36
|
+
if (root.nodeType === 1 && root.localName === tagName) return root;
|
|
37
|
+
return root.querySelector?.(tagName) ?? null;
|
|
38
|
+
}
|
|
39
|
+
function isHydrationSupportInstalled() {
|
|
40
|
+
const shadow = {};
|
|
41
|
+
const probe = { shadowRoot: shadow };
|
|
42
|
+
const createRenderRoot = lit.LitElement.prototype.createRenderRoot;
|
|
43
|
+
try {
|
|
44
|
+
return createRenderRoot.call(probe) === shadow;
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function partStartNode(part) {
|
|
50
|
+
return part?._$startNode ?? part?._$AA ?? null;
|
|
51
|
+
}
|
|
52
|
+
function isServerRootPart(part) {
|
|
53
|
+
const start = partStartNode(part);
|
|
54
|
+
return start?.nodeType === COMMENT_NODE && start.data.startsWith("lit-part");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* When a client render appended a separate tree beside the server DSD tree,
|
|
58
|
+
* keep only the server root part (plus preceding static style tags), remove the
|
|
59
|
+
* client anchors/children, and re-adopt the surviving server tree.
|
|
60
|
+
*/
|
|
61
|
+
function isolateServerTree(shadow) {
|
|
62
|
+
const children = Array.from(shadow.childNodes);
|
|
63
|
+
const rootIndex = children.findIndex((node) => node.nodeType === COMMENT_NODE && node.data.startsWith("lit-part"));
|
|
64
|
+
if (rootIndex < 0) return false;
|
|
65
|
+
let beginIndex = rootIndex;
|
|
66
|
+
while (beginIndex > 0) {
|
|
67
|
+
const previous = children[beginIndex - 1];
|
|
68
|
+
if (previous.nodeType === 1 && previous.localName === "style") {
|
|
69
|
+
beginIndex -= 1;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
let depth = 0;
|
|
75
|
+
let endIndex = -1;
|
|
76
|
+
for (let index = rootIndex; index < children.length; index += 1) {
|
|
77
|
+
const node = children[index];
|
|
78
|
+
if (node.nodeType !== COMMENT_NODE) continue;
|
|
79
|
+
const data = node.data;
|
|
80
|
+
if (data.startsWith("lit-part")) depth += 1;
|
|
81
|
+
else if (data.startsWith("/lit-part")) {
|
|
82
|
+
depth -= 1;
|
|
83
|
+
if (depth === 0) {
|
|
84
|
+
endIndex = index;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (endIndex < 0) return false;
|
|
90
|
+
for (let index = children.length - 1; index > endIndex; index -= 1) children[index].parentNode?.removeChild(children[index]);
|
|
91
|
+
for (let index = 0; index < beginIndex; index += 1) children[index].parentNode?.removeChild(children[index]);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function adoptServerShadow(host, shadow) {
|
|
95
|
+
host._$needsHydration = false;
|
|
96
|
+
host._$AG = false;
|
|
97
|
+
if (isolateServerTree(shadow)) {
|
|
98
|
+
delete shadow._$litPart$;
|
|
99
|
+
try {
|
|
100
|
+
const rendered = host.render();
|
|
101
|
+
(0, _lit_labs_ssr_client.hydrate)(rendered, shadow);
|
|
102
|
+
host.requestUpdate();
|
|
103
|
+
return;
|
|
104
|
+
} catch {}
|
|
105
|
+
}
|
|
106
|
+
shadow.replaceChildren();
|
|
107
|
+
delete shadow._$litPart$;
|
|
108
|
+
host.requestUpdate();
|
|
109
|
+
}
|
|
110
|
+
function hydrateHost(host) {
|
|
111
|
+
const shadow = host.shadowRoot;
|
|
112
|
+
if (!shadow) {
|
|
113
|
+
host.requestUpdate();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const hydrationSupportInstalled = isHydrationSupportInstalled();
|
|
117
|
+
if (!hydrationSupportInstalled) Object.defineProperty(host, "createRenderRoot", {
|
|
118
|
+
configurable: true,
|
|
119
|
+
value: () => shadow
|
|
120
|
+
});
|
|
121
|
+
const livePart = shadow._$litPart$;
|
|
122
|
+
if (livePart !== void 0) {
|
|
123
|
+
if (hasLitPartMarker(shadow) && !isServerRootPart(livePart)) {
|
|
124
|
+
adoptServerShadow(host, shadow);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
host.requestUpdate();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!hasLitPartMarker(shadow)) {
|
|
131
|
+
shadow.replaceChildren();
|
|
132
|
+
host.requestUpdate();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (hydrationSupportInstalled) {
|
|
136
|
+
host.requestUpdate();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const rendered = host.render();
|
|
140
|
+
(0, _lit_labs_ssr_client.hydrate)(rendered, shadow);
|
|
141
|
+
host.requestUpdate();
|
|
142
|
+
}
|
|
143
|
+
function upgradeServerHost(host, element) {
|
|
144
|
+
const tagName = element.localName;
|
|
145
|
+
const registry = globalThis.customElements;
|
|
146
|
+
if (!registry) throw new Error("hydrateLit() requires a DOM environment with customElements.");
|
|
147
|
+
if (!registry.get(tagName)) registry.define(tagName, element.constructor);
|
|
148
|
+
const existingShadow = host.shadowRoot;
|
|
149
|
+
if (existingShadow && !isHydrationSupportInstalled()) Object.defineProperty(host, "createRenderRoot", {
|
|
150
|
+
configurable: true,
|
|
151
|
+
value: () => existingShadow
|
|
152
|
+
});
|
|
153
|
+
const elementConstructor = element.constructor;
|
|
154
|
+
if (host instanceof elementConstructor) {
|
|
155
|
+
hydrateHost(host);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
registry.upgrade(host);
|
|
159
|
+
if (host instanceof elementConstructor) hydrateHost(host);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Hydrates server-produced markup on the client.
|
|
163
|
+
*
|
|
164
|
+
* Supported modes:
|
|
165
|
+
* 1. `root` is an element's own shadow root (or contains the Lit template
|
|
166
|
+
* markers produced by `renderLitTemplate`): the element's current template is
|
|
167
|
+
* hydrated into that root, preserving existing DOM and attaching event parts.
|
|
168
|
+
* 2. `root` contains a server-rendered custom element host for the same tag:
|
|
169
|
+
* the host is upgraded so its controllers and attributes connect.
|
|
170
|
+
* 3. `root` is empty: the element is mounted and rendered normally.
|
|
171
|
+
*
|
|
172
|
+
* The function never reads a global `document`; it operates only on the supplied
|
|
173
|
+
* root and element.
|
|
174
|
+
*/
|
|
175
|
+
function hydrateLit(root, element) {
|
|
176
|
+
if (!root || typeof root !== "object") throw new TypeError("hydrateLit() requires an Element or ShadowRoot.");
|
|
177
|
+
if (!element || typeof element !== "object") throw new TypeError("hydrateLit() requires a LitElement instance.");
|
|
178
|
+
const serverHost = findServerHost(root, element);
|
|
179
|
+
if (serverHost && serverHost !== element) {
|
|
180
|
+
upgradeServerHost(serverHost, element);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (root.nodeType === DOCUMENT_FRAGMENT_NODE && "host" in root && root.host === element) {
|
|
184
|
+
const shadow = root;
|
|
185
|
+
const livePart = shadow._$litPart$;
|
|
186
|
+
if (livePart === void 0) {
|
|
187
|
+
Object.defineProperty(element, "createRenderRoot", {
|
|
188
|
+
configurable: true,
|
|
189
|
+
value: () => shadow
|
|
190
|
+
});
|
|
191
|
+
if (hasLitPartMarker(shadow)) {
|
|
192
|
+
const rendered = element.render();
|
|
193
|
+
(0, _lit_labs_ssr_client.hydrate)(rendered, shadow);
|
|
194
|
+
} else shadow.replaceChildren();
|
|
195
|
+
} else if (hasLitPartMarker(shadow) && !isServerRootPart(livePart)) {
|
|
196
|
+
adoptServerShadow(element, shadow);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
element._$needsHydration = false;
|
|
200
|
+
element._$AG = false;
|
|
201
|
+
element.requestUpdate();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (hasLitPartMarker(root)) {
|
|
205
|
+
if (root._$litPart$ !== void 0) {
|
|
206
|
+
element.requestUpdate();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const rendered = element.render();
|
|
210
|
+
(0, _lit_labs_ssr_client.hydrate)(rendered, root);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (root !== element && !element.isConnected) root.append(element);
|
|
214
|
+
element.requestUpdate();
|
|
215
|
+
}
|
|
216
|
+
exports.hydrateLit = hydrateLit;
|
|
217
|
+
|
|
218
|
+
//# sourceMappingURL=hydrate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.cjs","names":["LitElement"],"sources":["../src/hydrate.ts"],"sourcesContent":["/**\n * @fileoverview Client-only hydration entry (`@context-action/lit-ui/hydrate`).\n *\n * This module intentionally imports only `@lit-labs/ssr-client` and the Lit\n * runtime, never the server renderer. Client bundles that only need\n * `hydrateLit()` can avoid pulling `@lit-labs/ssr` into the browser graph.\n *\n * @implements view-layer\n * @implements web-component-primitive\n * @memberof core-concepts\n */\n\nimport '@lit-labs/ssr-client/lit-element-hydrate-support.js';\nimport { LitElement } from 'lit';\nimport { hydrate } from '@lit-labs/ssr-client';\n\nconst COMMENT_NODE = 8;\nconst DOCUMENT_FRAGMENT_NODE = 11;\n\nfunction hasLitPartMarker(root: Element | ShadowRoot): boolean {\n const document = root.ownerDocument\n ?? (root as ShadowRoot).host?.ownerDocument\n ?? null;\n if (document && typeof document.createTreeWalker === 'function') {\n const walker = document.createTreeWalker(root, 128 /* NodeFilter.SHOW_COMMENT */);\n while (walker.nextNode()) {\n if ((walker.currentNode as Comment).data.startsWith('lit-part')) {\n return true;\n }\n }\n return false;\n }\n\n // Defensive fallback for environments without TreeWalker.\n for (let node = root.firstChild; node; node = node.nextSibling) {\n if (\n node.nodeType === COMMENT_NODE &&\n (node as Comment).data.startsWith('lit-part')\n ) {\n return true;\n }\n if (node.nodeType === 1 && hasLitPartMarker(node as Element)) {\n return true;\n }\n }\n return false;\n}\n\nfunction findServerHost(\n root: Element | ShadowRoot,\n element: LitElement,\n): Element | null {\n const tagName = element.localName;\n if (!tagName) return null;\n\n // A ShadowRoot owned by the element is a render target, not a host container.\n if (\n root.nodeType === DOCUMENT_FRAGMENT_NODE &&\n 'host' in root &&\n root.host === element\n ) {\n return null;\n }\n\n if (root.nodeType === 1 && (root as Element).localName === tagName) {\n return root as Element;\n }\n\n return root.querySelector?.(tagName) ?? null;\n}\n\nfunction isHydrationSupportInstalled(): boolean {\n const shadow = {};\n const probe = { shadowRoot: shadow } as unknown as LitElement;\n const createRenderRoot = (\n LitElement.prototype as unknown as {\n createRenderRoot(this: LitElement): unknown;\n }\n ).createRenderRoot;\n try {\n return createRenderRoot.call(probe) === shadow;\n } catch {\n return false;\n }\n}\n\ninterface LitPartLike {\n _$startNode?: Node | null;\n _$endNode?: Node | null;\n _$AA?: Node | null;\n _$AB?: Node | null;\n}\n\nfunction partStartNode(part: LitPartLike | undefined): Node | null {\n return part?._$startNode ?? part?._$AA ?? null;\n}\n\nfunction partEndNode(part: LitPartLike | undefined): Node | null {\n return part?._$endNode ?? part?._$AB ?? null;\n}\n\nfunction isServerRootPart(part: LitPartLike | undefined): boolean {\n const start = partStartNode(part);\n return (\n start?.nodeType === COMMENT_NODE &&\n (start as Comment).data.startsWith('lit-part')\n );\n}\n\n/**\n * When a client render appended a separate tree beside the server DSD tree,\n * keep only the server root part (plus preceding static style tags), remove the\n * client anchors/children, and re-adopt the surviving server tree.\n */\nfunction isolateServerTree(shadow: ShadowRoot): boolean {\n const children = Array.from(shadow.childNodes);\n const rootIndex = children.findIndex(\n node => node.nodeType === COMMENT_NODE && (node as Comment).data.startsWith('lit-part'),\n );\n if (rootIndex < 0) return false;\n\n let beginIndex = rootIndex;\n while (beginIndex > 0) {\n const previous = children[beginIndex - 1]!;\n if (previous.nodeType === 1 && (previous as Element).localName === 'style') {\n beginIndex -= 1;\n continue;\n }\n break;\n }\n\n let depth = 0;\n let endIndex = -1;\n for (let index = rootIndex; index < children.length; index += 1) {\n const node = children[index]!;\n if (node.nodeType !== COMMENT_NODE) continue;\n const data = (node as Comment).data;\n if (data.startsWith('lit-part')) {\n depth += 1;\n } else if (data.startsWith('/lit-part')) {\n depth -= 1;\n if (depth === 0) {\n endIndex = index;\n break;\n }\n }\n }\n if (endIndex < 0) return false;\n\n for (let index = children.length - 1; index > endIndex; index -= 1) {\n children[index]!.parentNode?.removeChild(children[index]!);\n }\n for (let index = 0; index < beginIndex; index += 1) {\n children[index]!.parentNode?.removeChild(children[index]!);\n }\n return true;\n}\n\nfunction adoptServerShadow(host: LitElement, shadow: ShadowRoot): void {\n // Clear Lit hydration support flags so the following requestUpdate does not\n // adopt the same tree a second time.\n (host as unknown as { _$needsHydration?: boolean })._$needsHydration = false;\n (host as unknown as { _$AG?: boolean })._$AG = false;\n\n if (isolateServerTree(shadow)) {\n delete (shadow as ShadowRoot & { _$litPart$?: unknown })._$litPart$;\n try {\n const rendered = (host as unknown as { render(): unknown }).render();\n hydrate(rendered, shadow);\n host.requestUpdate();\n return;\n } catch {\n // Fall through to a clean client render when the server tree cannot be\n // adopted (for example after an incompatible template change).\n }\n }\n\n shadow.replaceChildren();\n delete (shadow as ShadowRoot & { _$litPart$?: unknown })._$litPart$;\n host.requestUpdate();\n}\n\nfunction hydrateHost(host: LitElement): void {\n const shadow = host.shadowRoot;\n if (!shadow) {\n host.requestUpdate();\n return;\n }\n\n const hydrationSupportInstalled = isHydrationSupportInstalled();\n if (!hydrationSupportInstalled) {\n Object.defineProperty(host, 'createRenderRoot', {\n configurable: true,\n value: () => shadow,\n });\n }\n\n const livePart = (shadow as ShadowRoot & { _$litPart$?: LitPartLike })._$litPart$;\n if (livePart !== undefined) {\n if (hasLitPartMarker(shadow) && !isServerRootPart(livePart)) {\n adoptServerShadow(host, shadow);\n return;\n }\n host.requestUpdate();\n return;\n }\n\n if (!hasLitPartMarker(shadow)) {\n // Server markup without lit-html markers cannot be hydrated. Clear it and\n // force the first client render into this shadow root without asking Lit's\n // hydration support to adopt a non-lit tree.\n shadow.replaceChildren();\n host.requestUpdate();\n return;\n }\n\n // Lit's official hydration support patches createRenderRoot/update and\n // adopts the declarative shadow root on the first update. Running hydrate()\n // ourselves would make support hydrate the same container twice.\n if (hydrationSupportInstalled) {\n host.requestUpdate();\n return;\n }\n\n const rendered = (host as unknown as { render(): unknown }).render();\n hydrate(rendered, shadow);\n host.requestUpdate();\n}\n\nfunction upgradeServerHost(host: Element, element: LitElement): void {\n const tagName = element.localName;\n const registry = globalThis.customElements;\n if (!registry) {\n throw new Error('hydrateLit() requires a DOM environment with customElements.');\n }\n\n if (!registry.get(tagName)) {\n registry.define(tagName, element.constructor as CustomElementConstructor);\n }\n\n // A declarative shadow root already contains the server template. When Lit's\n // hydration support is not installed, prevent the first update from calling\n // attachShadow() on the same host. When support is installed, its patched\n // createRenderRoot already does this and must remain in control.\n const existingShadow = host.shadowRoot;\n if (existingShadow && !isHydrationSupportInstalled()) {\n Object.defineProperty(host, 'createRenderRoot', {\n configurable: true,\n value: () => existingShadow,\n });\n }\n\n const elementConstructor = element.constructor as unknown as { new (): LitElement };\n if (host instanceof elementConstructor) {\n hydrateHost(host);\n return;\n }\n\n registry.upgrade(host);\n if (host instanceof elementConstructor) {\n hydrateHost(host);\n }\n}\n\n/**\n * Hydrates server-produced markup on the client.\n *\n * Supported modes:\n * 1. `root` is an element's own shadow root (or contains the Lit template\n * markers produced by `renderLitTemplate`): the element's current template is\n * hydrated into that root, preserving existing DOM and attaching event parts.\n * 2. `root` contains a server-rendered custom element host for the same tag:\n * the host is upgraded so its controllers and attributes connect.\n * 3. `root` is empty: the element is mounted and rendered normally.\n *\n * The function never reads a global `document`; it operates only on the supplied\n * root and element.\n */\nexport function hydrateLit(root: Element | ShadowRoot, element: LitElement): void {\n if (!root || typeof root !== 'object') {\n throw new TypeError('hydrateLit() requires an Element or ShadowRoot.');\n }\n if (!element || typeof element !== 'object') {\n throw new TypeError('hydrateLit() requires a LitElement instance.');\n }\n\n const serverHost = findServerHost(root, element);\n if (serverHost && serverHost !== element) {\n upgradeServerHost(serverHost, element);\n return;\n }\n\n // The element's own shadow root is managed by its Lit update lifecycle.\n // Hydrate it explicitly and bypass the support flag so the first update does\n // not adopt the same container a second time.\n if (\n root.nodeType === DOCUMENT_FRAGMENT_NODE &&\n 'host' in root &&\n root.host === element\n ) {\n const shadow = root as ShadowRoot;\n const livePart = (shadow as ShadowRoot & { _$litPart$?: LitPartLike })._$litPart$;\n if (livePart === undefined) {\n Object.defineProperty(element, 'createRenderRoot', {\n configurable: true,\n value: () => shadow,\n });\n if (hasLitPartMarker(shadow)) {\n const rendered = (element as unknown as { render(): unknown }).render();\n hydrate(rendered, shadow);\n } else {\n shadow.replaceChildren();\n }\n } else if (hasLitPartMarker(shadow) && !isServerRootPart(livePart)) {\n adoptServerShadow(element, shadow);\n return;\n }\n // Support uses `_$needsHydration` in development and a minified field in\n // production. Clearing both is harmless when support is absent.\n (element as unknown as { _$needsHydration?: boolean })._$needsHydration = false;\n (element as unknown as { _$AG?: boolean })._$AG = false;\n element.requestUpdate();\n return;\n }\n\n if (hasLitPartMarker(root)) {\n const livePart = (root as ShadowRoot & { _$litPart$?: unknown })._$litPart$;\n if (livePart !== undefined) {\n element.requestUpdate();\n return;\n }\n const rendered = (element as unknown as { render(): unknown }).render();\n hydrate(rendered, root);\n return;\n }\n\n if (root !== element && !element.isConnected) {\n root.append(element);\n }\n element.requestUpdate();\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,eAAe;AACrB,MAAM,yBAAyB;AAE/B,SAAS,iBAAiB,MAAqC;CAC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8CAA8C;CAGpE,MAAM,aAAa,eAAe,MAAM,OAAO;CAC/C,IAAI,cAAc,eAAe,SAAS;EACxC,kBAAkB,YAAY,OAAO;EACrC;CACF;CAKA,IACE,KAAK,aAAa,0BAClB,UAAU,QACV,KAAK,SAAS,SACd;EACA,MAAM,SAAS;EACf,MAAM,WAAY,OAAqD;EACvE,IAAI,aAAa,KAAA,GAAW;GAC1B,OAAO,eAAe,SAAS,oBAAoB;IACjD,cAAc;IACd,aAAa;GACf,CAAC;GACD,IAAI,iBAAiB,MAAM,GAAG;IAC5B,MAAM,WAAY,QAA6C,OAAO;IACtE,CAAA,GAAA,qBAAA,QAAA,CAAQ,UAAU,MAAM;GAC1B,OACE,OAAO,gBAAgB;EAE3B,OAAO,IAAI,iBAAiB,MAAM,KAAK,CAAC,iBAAiB,QAAQ,GAAG;GAClE,kBAAkB,SAAS,MAAM;GACjC;EACF;EAGA,QAAuD,mBAAmB;EAC1E,QAA2C,OAAO;EAClD,QAAQ,cAAc;EACtB;CACF;CAEA,IAAI,iBAAiB,IAAI,GAAG;EAE1B,IADkB,KAA+C,eAChD,KAAA,GAAW;GAC1B,QAAQ,cAAc;GACtB;EACF;EACA,MAAM,WAAY,QAA6C,OAAO;EACtE,CAAA,GAAA,qBAAA,QAAA,CAAQ,UAAU,IAAI;EACtB;CACF;CAEA,IAAI,SAAS,WAAW,CAAC,QAAQ,aAC/B,KAAK,OAAO,OAAO;CAErB,QAAQ,cAAc;AACxB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "@lit-labs/ssr-client/lit-element-hydrate-support.js";
|
|
2
|
+
import { LitElement } from "lit";
|
|
3
|
+
/**
|
|
4
|
+
* Hydrates server-produced markup on the client.
|
|
5
|
+
*
|
|
6
|
+
* Supported modes:
|
|
7
|
+
* 1. `root` is an element's own shadow root (or contains the Lit template
|
|
8
|
+
* markers produced by `renderLitTemplate`): the element's current template is
|
|
9
|
+
* hydrated into that root, preserving existing DOM and attaching event parts.
|
|
10
|
+
* 2. `root` contains a server-rendered custom element host for the same tag:
|
|
11
|
+
* the host is upgraded so its controllers and attributes connect.
|
|
12
|
+
* 3. `root` is empty: the element is mounted and rendered normally.
|
|
13
|
+
*
|
|
14
|
+
* The function never reads a global `document`; it operates only on the supplied
|
|
15
|
+
* root and element.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hydrateLit(root: Element | ShadowRoot, element: LitElement): void;
|
|
18
|
+
//# sourceMappingURL=hydrate.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrate.d.cts","names":[],"sources":["../src/hydrate.ts"],"mappings":";;;;;;;;;;;;;;;;wBAsRgB,WAAW,MAAM,UAAU,YAAY,SAAS"}
|