Skip to content

Commit e091f23

Browse files
committed
04/09 meeting feedback
1 parent ccbd9f3 commit e091f23

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

text/0112-server-runtime.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class App extends LightningElement {}
5757
**`client.js`:**
5858

5959
```js
60-
import { createElement } from "lwc"; // Aliased to @lwc/engine-dom
60+
import { createElement } from "@lwc/engine-dom";
6161
import App from "c/app";
6262

6363
const app = createElement("c-app", { is: App });
@@ -67,7 +67,7 @@ document.body.appendChild(app);
6767
**`server.js`:**
6868

6969
```js
70-
import { createElement, renderToString } from "lwc"; // Aliased to @lwc/engine-server
70+
import { createElement, renderToString } from "@lwc/engine-server";
7171
import App from "c/app";
7272

7373
const app = createElement("c-app", { is: App });
@@ -102,19 +102,24 @@ The DOM APIs used by the rendered engine are injected by the runtime depending o
102102
This package exposes the following APIs:
103103

104104
- `createElement` + reaction hooks
105-
- `buildCustomElementConstructor`
106105
- `isNodeFromTemplate`
107106

108107
This package injects the native DOM APIs into the `@lwc/engine-core` rendering engine.
109108

110109
### `@lwc/engine-server`
111110

112-
This package exposes the following APIs:
111+
This package exposes the following API:
112+
113+
- `renderComponent(name: string, ctor: typeof LightningElement, props?: Record<string, any>): string`: This method creates an renders an LWC component synchronously to a string.
114+
115+
When a component is rendered using `renderComponent`, the following restriction applies:
116+
- each created component will execute the following life-cycle hooks once `constructor`, `connectedCallback` and `render`
117+
- properties and methods annotated with `@wire` will not be invoked
118+
- component reactivity is disabled
113119

114-
- `createElement(name: string, options: { is: typeof LightningElement }): ServerHTMLElement`: This method creates a new LWC component tree. It follows the same signature as the `createElement` API from `@lwc/engine-dom`. Instead of returning a native `HTMLElement`, this method returns a `ServerHTMLElement` with the public properties, aria reflected properties and HTML global attributed.
115-
- `renderToString(element: ServerHTMLElement): string`: This method synchronously serializes an LWC component tree to HTML. It accepts a single parameter, a `ServerHTMLElement` returned by `createElement` and returns the serialized string.
120+
Another API might be created to accommodate wire adapter invocation and asynchronous data fetching on the server.
116121

117-
This package injects mock DOM APIs in the `@lwc/engine-core` rendering engine. Those DOM APIs produce a lightweight DOM structure. This structure can then be serialized into a string containing the HTML serialization of the element's descendants. As described in the Appendix, this package is also in charge of attaching on the global object a mock `CustomEvent`.
122+
This package injects mock DOM APIs in the `@lwc/engine-core` rendering engine. Those DOM APIs produce a lightweight DOM structure. This structure can then be serialized into a string containing the HTML serialization of the element's descendants. As described in the Appendix, this package is also in charge of attaching on the global object a mock `CustomEvent` and only implements a restricted subset of the event dispatching algorithm on the server (no bubbling, no event retargeting).
118123

119124
## Drawbacks
120125

@@ -132,21 +137,14 @@ There are multiple drawbacks with this approach:
132137
- Performance: The engine only relies on a limited set of well-known APIs, leveraging a full DOM implementation for SSR would greatly reduce the SSR performance.
133138
- Predictability: By attaching the DOM interfaces on the global object, those APIs are not only exposed to the engine but also to the component author. Exposing such APIs to the component author might bring unexpected behavior when component code runs on the server.
134139

135-
## Adoption strategy
136-
137-
TBD
138-
139140
## How we teach this
140141

141-
TBD
142-
143-
## Unresolved questions
142+
This proposal breaks up the existing `@lwc/engine` package into multiple packages. Because of this APIs that used to be imported from `lwc` might not be present anymore. With this proposal, the `createElement` API will be moving to `@lwc/engine-dom`. This change constitutes a breaking change by itself, so we need to be careful how this change will be released. The good news is that `createElement` is considered as an experimental API and should only used to create the application root and to test components.
144143

145-
**How to load the right version of the engine when resolving the `lwc` identifier?**
144+
Changing the application root creation consists in a one line change. Therefor it should be pretty straightforward updated as long as it is well documented. Updating all the usages of `createElement` in test will probably require more time. For testing purposes, the `lwc` module will be mapped to the `@lwc/engine-dom` instead of `@lwc/engine-core` for now. We will also add warning messages in the console to promulgate the new pattern. A codemod for test files can also be used rename the `lwc` import in the test files to `@lwc/engine-dom`.
146145

147-
For example, when running in Node.js `lwc` might resolve to `@lwc/engine-server` for SSR purposes, but also to `@lwc/engine-dom` when running test via jest and jsdom.
148146

149-
One way to solve this would be to import the platform-specific APIs from the appropriate module: `createElement` from `@lwc/engine-dom` and `createElement` and `renderToString` from `@lwc/engine-server`. Platform-agnostic APIs should be imported from `lwc` (which becomes an alias to `@lwc/engine-core`).
147+
Updating the documentation for the newly added server only APIs should be enough.
150148

151149
---
152150

0 commit comments

Comments
 (0)