@mdn/fred 2.1.0 → 2.2.0
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 +21 -0
- package/README.md +18 -0
- package/build/server-worker.js +6 -4
- package/components/doc/server.js +9 -1
- package/components/outer-layout/server.js +8 -7
- package/components/reference-layout/server.js +14 -0
- package/components/server/async-local-storage.js +12 -1
- package/components/server/index.js +16 -1
- package/components/server/types.d.ts +9 -5
- package/entry.ssr.js +33 -1
- package/out/service-worker.js +1 -1
- package/out/service-worker.js.map +1 -1
- package/out/static/client/{3730.1a4ba03239ff0f16.js → 3730.dcf04b12bbd00d6f.js} +2 -2
- package/out/static/client/{3730.1a4ba03239ff0f16.js.map → 3730.dcf04b12bbd00d6f.js.map} +1 -1
- package/out/static/client/6216.1bfd3cf0b0a6c7df.js +2 -0
- package/out/static/client/6216.1bfd3cf0b0a6c7df.js.map +1 -0
- package/out/static/client/8233.ae0b9ab7bd3e969b.js +2 -0
- package/out/static/client/8233.ae0b9ab7bd3e969b.js.map +1 -0
- package/out/static/client/{index.0e1f202766cdb426.js → index.a66b5a087a738e61.js} +3 -3
- package/out/static/client/{index.0e1f202766cdb426.js.map → index.a66b5a087a738e61.js.map} +1 -1
- package/out/static/client/{runtime.076e84c93222dfd0.js → runtime.149f3caaca6b394a.js} +2 -2
- package/out/static/client/{runtime.076e84c93222dfd0.js.map → runtime.149f3caaca6b394a.js.map} +1 -1
- package/out/static/client/stats.json +436 -436
- package/out/static/client/styles-a11y-menu.b09c6038ee60691b.js +1 -0
- package/out/static/client/styles-advertising.8a72634ac33967b3.js +1 -0
- package/out/static/client/styles-article-footer.2008e05e900132bf.js +1 -0
- package/out/static/client/styles-banner.1588da63ad451f94.js +1 -0
- package/out/static/client/styles-baseline-indicator.045ce266c0388ff2.js +1 -0
- package/out/static/client/styles-blog-index.af7e5efac0463be9.js +1 -0
- package/out/static/client/styles-blog-post.21543a25c5d0c820.js +1 -0
- package/out/static/client/styles-breadcrumbs-bar.4e50455c81d9f236.js +1 -0
- package/out/static/client/styles-breadcrumbs.3272f39f147fdb26.js +1 -0
- package/out/static/client/styles-button.93e42cbce83fe9f8.js +1 -0
- package/out/static/client/styles-content-section.b38423c0dca8e3e4.js +1 -0
- package/out/static/client/styles-contributor-spotlight.efe854e18205bd6c.js +1 -0
- package/out/static/client/styles-curriculum-about.eb719efa09eab2e3.js +1 -0
- package/out/static/client/styles-curriculum-default.648a02845551d4a6.js +1 -0
- package/out/static/client/styles-curriculum-landing.f3af2ff9b3815ed8.js +1 -0
- package/out/static/client/styles-curriculum-module.284687a631bdb6c0.js +1 -0
- package/out/static/client/styles-curriculum-overview.81d25abdbb43b369.js +1 -0
- package/out/static/client/styles-featured-articles.1390540e6554e233.js +1 -0
- package/out/static/client/styles-footer.15153a4030e38f8f.js +1 -0
- package/out/static/client/styles-generic-about.f0afaa2db7066430.js +1 -0
- package/out/static/client/styles-generic-community.ff945b87102835f8.js +1 -0
- package/out/static/client/styles-generic-content.d0e560a0506475b1.js +1 -0
- package/out/static/client/styles-generic-layout.ca2cef837e24e7df.js +1 -0
- package/out/static/client/styles-generic-sidebar.b2b48d0d08f8bae7.js +1 -0
- package/out/static/client/styles-generic-toc.e8887bbe84a31d72.js +1 -0
- package/out/static/client/{styles-global.63980d9c69df1f6a.css → styles-global.2db431c11b66274e.css} +2 -2
- package/out/static/client/{styles-global.63980d9c69df1f6a.css.map → styles-global.2db431c11b66274e.css.map} +1 -1
- package/out/static/client/styles-global.efc5040b727dfca4.js +1 -0
- package/out/static/client/styles-heading-anchor.d7e14184517a1d3e.js +1 -0
- package/out/static/client/styles-homepage-body.1196a061fab22906.js +1 -0
- package/out/static/client/styles-homepage-contributor-spotlight.09a6993f73166d63.js +1 -0
- package/out/static/client/styles-homepage-footer.472132358e452a8b.js +1 -0
- package/out/static/client/styles-homepage-header.e6423ccb0a814f99.js +1 -0
- package/out/static/client/styles-homepage-hero.1c106d7a3adb970a.js +1 -0
- package/out/static/client/styles-homepage.843ab43d3f720fb6.js +1 -0
- package/out/static/client/styles-latest-news.986caae0711fbfe3.js +1 -0
- package/out/static/client/styles-left-sidebar.5a4d56fc21aab182.js +1 -0
- package/out/static/client/styles-logo.9cf3aa133bae8020.js +1 -0
- package/out/static/client/styles-mandala.b9822fc945abee39.js +1 -0
- package/out/static/client/styles-menu.97e048a6ffc666ce.js +1 -0
- package/out/static/client/styles-navigation.58a2a0a1f8d4487b.js +1 -0
- package/out/static/client/styles-not-found.a5c00a725a178969.js +1 -0
- package/out/static/client/styles-observatory-landing.c729a3523c37df23.js +1 -0
- package/out/static/client/styles-observatory-results.d4d142541bf683e1.js +1 -0
- package/out/static/client/styles-page-layout.baa1dac2402744c9.js +1 -0
- package/out/static/client/styles-pagination.04e3a505f4e789a6.js +1 -0
- package/out/static/client/styles-playground.7de5e497e2ebfa83.js +1 -0
- package/out/static/client/styles-recent-contributions.f1ab270b54c7e8de.js +1 -0
- package/out/static/client/styles-reference-layout.5c4b832bc9420f51.js +1 -0
- package/out/static/client/styles-reference-toc.afd507fb6d5ef895.js +1 -0
- package/out/static/client/styles-sandbox.3de7bd2afac30c66.js +1 -0
- package/out/static/client/styles-site-search.05f228cb7ac309b2.js +1 -0
- package/out/static/client/styles-social-image.dbdccf6b8d9258f2.js +1 -0
- package/out/static/client/styles-translation-banner.7698ddb14a70d0e5.js +1 -0
- package/out/static/client/styles-writer-toolbar.f161f8bd86e23a2a.js +1 -0
- package/out/static/client/{styles.cbf2ca4b84823096.js → styles.a182af71488aad03.js} +2 -2
- package/out/static/client/{styles.cbf2ca4b84823096.js.map → styles.a182af71488aad03.js.map} +1 -1
- package/out/static/client/watify_bg.4b1c94ba3861176a.wasm +0 -0
- package/out/static/legacy/{2569.41b52dfae9ff5dbd.js → 2569.9f096bac448374bd.js} +2 -2
- package/out/static/legacy/{2569.41b52dfae9ff5dbd.js.map → 2569.9f096bac448374bd.js.map} +1 -1
- package/out/static/legacy/6753.c44647828e8b4816.js +27 -0
- package/out/static/legacy/6753.c44647828e8b4816.js.map +1 -0
- package/out/static/legacy/7555.7cda2207795611e9.js +2 -0
- package/out/static/legacy/7555.7cda2207795611e9.js.map +1 -0
- package/out/static/legacy/8233.ae0b9ab7bd3e969b.js +2 -0
- package/out/static/legacy/8233.ae0b9ab7bd3e969b.js.map +1 -0
- package/out/static/legacy/asset-manifest.json +11 -11
- package/out/static/legacy/{index.5e65b9f52e86ad40.js → index.6c7371784b8345e6.js} +3 -3
- package/out/static/legacy/{index.5e65b9f52e86ad40.js.map → index.6c7371784b8345e6.js.map} +1 -1
- package/out/static/legacy/{index.6838304b64f32836.html → index.7ddac90f21db9f4e.html} +1 -1
- package/out/static/legacy/stats.json +13 -13
- package/out/static/legacy/watify_bg.4b1c94ba3861176a.wasm +0 -0
- package/out/static/legacy/{yari.c8f274d3a31b194e.js → yari.74e397a2236facc5.js} +4 -4
- package/out/static/legacy/yari.74e397a2236facc5.js.map +1 -0
- package/out/static/ssr/8233.js +1 -1
- package/out/static/ssr/8233.js.map +1 -1
- package/out/static/ssr/index.js +136 -133
- package/out/static/ssr/index.js.map +1 -1
- package/out/static/ssr/stats.json +4 -4
- package/out/static/ssr/watify_bg.4b1c94ba3861176a.wasm +0 -0
- package/package.json +20 -20
- package/out/static/client/6216.e1ccb610706d375f.js +0 -2
- package/out/static/client/6216.e1ccb610706d375f.js.map +0 -1
- package/out/static/client/8233.81b8c2d171f5ea9f.js +0 -2
- package/out/static/client/8233.81b8c2d171f5ea9f.js.map +0 -1
- package/out/static/client/styles-a11y-menu.bf24a870a8a4969f.js +0 -1
- package/out/static/client/styles-advertising.9f2b7bddc08575fc.js +0 -1
- package/out/static/client/styles-article-footer.aa9f8d240980b0f4.js +0 -1
- package/out/static/client/styles-banner.e738836bac789a8b.js +0 -1
- package/out/static/client/styles-baseline-indicator.c062716f3d033dd8.js +0 -1
- package/out/static/client/styles-blog-index.818261c8123bc042.js +0 -1
- package/out/static/client/styles-blog-post.96ce1680245bbc86.js +0 -1
- package/out/static/client/styles-breadcrumbs-bar.ed7d1440bdccf98f.js +0 -1
- package/out/static/client/styles-breadcrumbs.7599a269dc584d75.js +0 -1
- package/out/static/client/styles-button.de6a7b9b7548d84b.js +0 -1
- package/out/static/client/styles-content-section.a8bd7fde04898354.js +0 -1
- package/out/static/client/styles-contributor-spotlight.adad2e813e1667fe.js +0 -1
- package/out/static/client/styles-curriculum-about.eefa128bb415258c.js +0 -1
- package/out/static/client/styles-curriculum-default.a2692218d2b1a1f9.js +0 -1
- package/out/static/client/styles-curriculum-landing.2d51b8fce8f12b8d.js +0 -1
- package/out/static/client/styles-curriculum-module.f4ae8920ee1c92ff.js +0 -1
- package/out/static/client/styles-curriculum-overview.2d7c17b0f0b9bd92.js +0 -1
- package/out/static/client/styles-featured-articles.c54e8f6b90567441.js +0 -1
- package/out/static/client/styles-footer.cff8d2b7669e06a9.js +0 -1
- package/out/static/client/styles-generic-about.b31b672a5d394108.js +0 -1
- package/out/static/client/styles-generic-community.f7e5df670c7aeaf3.js +0 -1
- package/out/static/client/styles-generic-content.1a9e4b87d8a12a85.js +0 -1
- package/out/static/client/styles-generic-layout.76e37948146a2f39.js +0 -1
- package/out/static/client/styles-generic-sidebar.c07d266d1382c357.js +0 -1
- package/out/static/client/styles-generic-toc.342bb77a42e3cc84.js +0 -1
- package/out/static/client/styles-global.c2e6118d3b833b4a.js +0 -1
- package/out/static/client/styles-heading-anchor.79390408a0c88875.js +0 -1
- package/out/static/client/styles-homepage-body.20c015a218d0bc96.js +0 -1
- package/out/static/client/styles-homepage-contributor-spotlight.21f37f11b3bd4bda.js +0 -1
- package/out/static/client/styles-homepage-footer.24e66b627b59d99f.js +0 -1
- package/out/static/client/styles-homepage-header.1a75fa94f8bab5a0.js +0 -1
- package/out/static/client/styles-homepage-hero.f1bf55f1be2d516d.js +0 -1
- package/out/static/client/styles-homepage.cd5bf6213bc06b4e.js +0 -1
- package/out/static/client/styles-latest-news.0f32a584ef1ed171.js +0 -1
- package/out/static/client/styles-left-sidebar.d7d52289da7ba969.js +0 -1
- package/out/static/client/styles-logo.1ff82941fc133017.js +0 -1
- package/out/static/client/styles-mandala.2a99de27a8c19d02.js +0 -1
- package/out/static/client/styles-menu.13c3394ada0512ef.js +0 -1
- package/out/static/client/styles-navigation.f857f577084aa7ef.js +0 -1
- package/out/static/client/styles-not-found.0bdc6a72643ebe34.js +0 -1
- package/out/static/client/styles-observatory-landing.e709efc8103ee08c.js +0 -1
- package/out/static/client/styles-observatory-results.e098740504c0c0f0.js +0 -1
- package/out/static/client/styles-page-layout.2ab75fc5b95edf1b.js +0 -1
- package/out/static/client/styles-pagination.667a2af3eaebe782.js +0 -1
- package/out/static/client/styles-playground.c1339745dabdf1f6.js +0 -1
- package/out/static/client/styles-recent-contributions.706333df420f227c.js +0 -1
- package/out/static/client/styles-reference-layout.6eaaea648e7e4dce.js +0 -1
- package/out/static/client/styles-reference-toc.dcb67aadb5032e3f.js +0 -1
- package/out/static/client/styles-sandbox.c14203f7b76d9e70.js +0 -1
- package/out/static/client/styles-site-search.ba674569591c3348.js +0 -1
- package/out/static/client/styles-social-image.f457942a12584899.js +0 -1
- package/out/static/client/styles-translation-banner.c0bf41a60bc2fe87.js +0 -1
- package/out/static/client/styles-writer-toolbar.e7438b6d8e7c99f4.js +0 -1
- package/out/static/client/watify_bg.dc8862fe10114050.wasm +0 -0
- package/out/static/legacy/6753.553d1b0c7912acfe.js +0 -27
- package/out/static/legacy/6753.553d1b0c7912acfe.js.map +0 -1
- package/out/static/legacy/7555.499540c46b2d1bd3.js +0 -2
- package/out/static/legacy/7555.499540c46b2d1bd3.js.map +0 -1
- package/out/static/legacy/8233.81b8c2d171f5ea9f.js +0 -2
- package/out/static/legacy/8233.81b8c2d171f5ea9f.js.map +0 -1
- package/out/static/legacy/watify_bg.dc8862fe10114050.wasm +0 -0
- package/out/static/legacy/yari.c8f274d3a31b194e.js.map +0 -1
- package/out/static/ssr/watify_bg.dc8862fe10114050.wasm +0 -0
- /package/out/{twitter-card-summary.46ac2375.png → mdn-social-image.46ac2375.png} +0 -0
- /package/out/static/client/{index.0e1f202766cdb426.js.LICENSE.txt → index.a66b5a087a738e61.js.LICENSE.txt} +0 -0
- /package/out/static/legacy/{6753.553d1b0c7912acfe.js.LICENSE.txt → 6753.c44647828e8b4816.js.LICENSE.txt} +0 -0
- /package/out/static/legacy/{index.5e65b9f52e86ad40.js.LICENSE.txt → index.6c7371784b8345e6.js.LICENSE.txt} +0 -0
- /package/out/static/legacy/{yari.c8f274d3a31b194e.js.LICENSE.txt → yari.74e397a2236facc5.js.LICENSE.txt} +0 -0
- /package/public/{twitter-card-summary.46ac2375.png → mdn-social-image.46ac2375.png} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.0](https://github.com/mdn/fred/compare/v2.1.0...v2.2.0) (2026-02-02)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **ServerComponent:** add method to render simplified html ([#1072](https://github.com/mdn/fred/issues/1072)) ([fa6c814](https://github.com/mdn/fred/commit/fa6c8143505b8f7629f90adf1bb1e5a5b3dadb54))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **outer-layout:** avoid `summary_large_image` in `twitter:card` ([#1227](https://github.com/mdn/fred/issues/1227)) ([dd47e77](https://github.com/mdn/fred/commit/dd47e77d6e320751d6219d4ed13f5254687d773a))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Miscellaneous
|
|
17
|
+
|
|
18
|
+
* **deps-dev:** bump @mdn/browser-compat-data from 7.2.5 to 7.3.0 ([#1268](https://github.com/mdn/fred/issues/1268)) ([519f3ad](https://github.com/mdn/fred/commit/519f3adf1a3812e7c5d1eaa90ecbef2d57a7ff86))
|
|
19
|
+
* **deps-dev:** bump the dev group across 1 directory with 8 updates ([#1262](https://github.com/mdn/fred/issues/1262)) ([bf48e08](https://github.com/mdn/fred/commit/bf48e08a92a69532397937586f073879db6f061c))
|
|
20
|
+
* **deps-dev:** bump the dev group with 10 updates ([#1267](https://github.com/mdn/fred/issues/1267)) ([af4a569](https://github.com/mdn/fred/commit/af4a569a4506b1da190294e45f3676f5ff6341a2))
|
|
21
|
+
* **deps:** bump @mdn/watify from 1.1.7 to 1.1.8 ([#1271](https://github.com/mdn/fred/issues/1271)) ([e2c10f9](https://github.com/mdn/fred/commit/e2c10f9fcbef36b5dbf9135777441f0923386e6b))
|
|
22
|
+
* **deps:** bump tar from 7.5.6 to 7.5.7 ([#1264](https://github.com/mdn/fred/issues/1264)) ([0ae1ccd](https://github.com/mdn/fred/commit/0ae1ccd2ed24fc720f011d80e8c6ab83ea773811))
|
|
23
|
+
|
|
3
24
|
## [2.1.0](https://github.com/mdn/fred/compare/v2.0.2...v2.1.0) (2026-01-27)
|
|
4
25
|
|
|
5
26
|
|
package/README.md
CHANGED
|
@@ -159,3 +159,21 @@ If our server side rendered custom elements are different to the initial state o
|
|
|
159
159
|
To avoid this, don't compute things that are server/client dependent in `connectedCallback` (or run functions which do this). Instead you must run these in `firstUpdated` (despite the warning lit will raise in development about the element scheduling an update after an update completed).
|
|
160
160
|
|
|
161
161
|
This issue is tracked upstream: https://github.com/lit/lit/issues/1434
|
|
162
|
+
|
|
163
|
+
### Simplified HTML
|
|
164
|
+
|
|
165
|
+
`entry.ssr.js` exports a top-level `renderSimplified` function: the purpose of this is to render a very basic HTML page for a particular path, which is useful for embedding MDN content as templated HTML in other contexts.
|
|
166
|
+
|
|
167
|
+
Any server component can define a `renderSimplified` method to define the simplified form of that component. When in the top-level `renderSimplified` context, any calls of `ServerComponent.render()` will automatically call the `renderSimplified` method of that component, falling back to the `render` method. This is so we can nest components with a `renderSimplified` method ("simplified components") within ones without.
|
|
168
|
+
|
|
169
|
+
There shouldn't be standalone simplified components: the nesting of components should be defined by the requirements of the `render` method. `renderSimplified` should only be added to a component which already exists with a `render` method to give a simplified view of it. This is especially important as, in the future, we may need to add options of what is/isn't rendered within `renderSimplified` for use in different contexts (one context may require a sidebar, another may not, for instance).
|
|
170
|
+
|
|
171
|
+
You can preview the rendering locally by setting `FRED_SIMPLE_HTML`:
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
FRED_SIMPLE_HTML=true npm run start
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Then visit a documentation path directly, e.g. http://localhost:3000/en-US/docs/Web/
|
|
178
|
+
|
|
179
|
+
If you're loading a path which isn't rendering anything (like the homepage), check if it's defined in `renderSimplified` in `entry.ssr.js`: we "opt-in" routes as we need them.
|
package/build/server-worker.js
CHANGED
|
@@ -28,10 +28,12 @@ if (!indexModulePath) {
|
|
|
28
28
|
try {
|
|
29
29
|
/** @type {import("../entry.ssr.js")} */
|
|
30
30
|
const indexModule = await import(pathToFileURL(indexModulePath).href);
|
|
31
|
-
const html =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const html = process.env.FRED_SIMPLE_HTML
|
|
32
|
+
? `<!doctype html><meta charset="UTF-8">${await indexModule?.renderSimplified(reqPath, context)}`
|
|
33
|
+
: await indexModule?.render(reqPath, context, {
|
|
34
|
+
client: compilationStats.find((x) => x.name === "client") || {},
|
|
35
|
+
legacy: compilationStats.find((x) => x.name === "legacy") || {},
|
|
36
|
+
});
|
|
35
37
|
parentPort?.postMessage({ html });
|
|
36
38
|
} catch (error) {
|
|
37
39
|
parentPort?.postMessage({ error });
|
package/components/doc/server.js
CHANGED
|
@@ -5,8 +5,16 @@ import { ServerComponent } from "../server/index.js";
|
|
|
5
5
|
export class Doc extends ServerComponent {
|
|
6
6
|
/**
|
|
7
7
|
* @param {import("@fred").Context<import("@rari").DocPage>} context
|
|
8
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
render(context) {
|
|
9
10
|
context.pageTitle = context.doc.pageTitle;
|
|
10
11
|
return PageLayout.render(context, ReferenceLayout.render(context));
|
|
11
12
|
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {import("@fred").Context<import("@rari").DocPage>} context
|
|
16
|
+
*/
|
|
17
|
+
renderSimplified(context) {
|
|
18
|
+
return ReferenceLayout.render(context);
|
|
19
|
+
}
|
|
12
20
|
}
|
|
@@ -26,6 +26,9 @@ export class OuterLayout extends ServerComponent {
|
|
|
26
26
|
if (!asyncStore) {
|
|
27
27
|
throw new Error("asyncLocalStorage missing");
|
|
28
28
|
}
|
|
29
|
+
if ("renderSimplified" in asyncStore) {
|
|
30
|
+
throw new Error("OuterLayout called from renderSimplified function");
|
|
31
|
+
}
|
|
29
32
|
const { componentsUsed, componentsWithStylesInHead, compilationStats } =
|
|
30
33
|
asyncStore;
|
|
31
34
|
|
|
@@ -173,15 +176,13 @@ export class OuterLayout extends ServerComponent {
|
|
|
173
176
|
"og:title": title,
|
|
174
177
|
"og:locale": context.locale.replace("-", "_"),
|
|
175
178
|
"og:description": description,
|
|
176
|
-
"og:image":
|
|
177
|
-
"https://developer.mozilla.org/mdn-social-share.d893525a4fb5fb1f67a2.png",
|
|
179
|
+
"og:image": "https://developer.mozilla.org/mdn-social-image.46ac2375.png",
|
|
178
180
|
"og:image:type": "image/png",
|
|
179
|
-
"og:image:height": "
|
|
180
|
-
"og:image:width": "
|
|
181
|
-
"og:image:alt":
|
|
182
|
-
"The MDN Web Docs logo, featuring a blue accent color, displayed on a solid black background.",
|
|
181
|
+
"og:image:height": "1024",
|
|
182
|
+
"og:image:width": "1024",
|
|
183
|
+
"og:image:alt": "The MDN logo",
|
|
183
184
|
"og:site_name": "MDN Web Docs",
|
|
184
|
-
"twitter:card": "
|
|
185
|
+
"twitter:card": "summary",
|
|
185
186
|
"twitter:creator": "MozDevNet",
|
|
186
187
|
};
|
|
187
188
|
|
|
@@ -44,4 +44,18 @@ export class ReferenceLayout extends ServerComponent {
|
|
|
44
44
|
</div>
|
|
45
45
|
`;
|
|
46
46
|
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {import("@fred").Context<import("@rari").DocPage>} context
|
|
50
|
+
*/
|
|
51
|
+
renderSimplified(context) {
|
|
52
|
+
const { doc } = context;
|
|
53
|
+
const sections =
|
|
54
|
+
doc.body?.map((section) => ContentSection.render(context, section)) || [];
|
|
55
|
+
|
|
56
|
+
return html`
|
|
57
|
+
<h1>${doc.title}</h1>
|
|
58
|
+
${BaselineIndicator.render(context)} ${sections}
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
47
61
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Store for internal context passed around components.
|
|
5
|
+
*
|
|
6
|
+
* Generally only used within the `ServerComponent` class itself,
|
|
7
|
+
* or very special server components (such as the `OuterLayout`).
|
|
8
|
+
*
|
|
9
|
+
* e.g. We add the rspack compilation stats for use in `OuterLayout`.
|
|
10
|
+
*
|
|
11
|
+
* Populated in `entry.ssr.js`.
|
|
12
|
+
*
|
|
13
|
+
* @type {AsyncLocalStorage<import("./types.js").FredLocalContents>}
|
|
14
|
+
*/
|
|
4
15
|
export const asyncLocalStorage = new AsyncLocalStorage();
|
|
@@ -24,6 +24,13 @@ export class ServerComponent {
|
|
|
24
24
|
if (!asyncStore) {
|
|
25
25
|
throw new Error("asyncLocalStorage missing");
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
const component = new this();
|
|
29
|
+
|
|
30
|
+
if ("renderSimplified" in asyncStore) {
|
|
31
|
+
return component.renderSimplified(...args);
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
const { componentsUsed, componentsWithStylesInHead, compilationStats } =
|
|
28
35
|
asyncStore;
|
|
29
36
|
const componentUsedBefore = componentsUsed.has(this.name);
|
|
@@ -35,7 +42,7 @@ export class ServerComponent {
|
|
|
35
42
|
componentsUsed.add("legacy");
|
|
36
43
|
}
|
|
37
44
|
|
|
38
|
-
let res =
|
|
45
|
+
let res = component.render(...args);
|
|
39
46
|
|
|
40
47
|
if (!res || res === nothing) {
|
|
41
48
|
if (!componentUsedBefore) {
|
|
@@ -73,4 +80,12 @@ export class ServerComponent {
|
|
|
73
80
|
render(..._args) {
|
|
74
81
|
throw new Error("Must be implemented by subclass");
|
|
75
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @param {...any} args
|
|
86
|
+
* @returns {any}
|
|
87
|
+
*/
|
|
88
|
+
renderSimplified(...args) {
|
|
89
|
+
return this.render(...args);
|
|
90
|
+
}
|
|
76
91
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export type FredLocalContents =
|
|
2
|
+
| {
|
|
3
|
+
componentsUsed: Set<string>;
|
|
4
|
+
componentsWithStylesInHead: Set<string>;
|
|
5
|
+
compilationStats: import("@fred").CompilationStats;
|
|
6
|
+
}
|
|
7
|
+
| {
|
|
8
|
+
renderSimplified: true;
|
|
9
|
+
};
|
package/entry.ssr.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { render as r } from "@lit-labs/ssr";
|
|
3
3
|
import { collectResult } from "@lit-labs/ssr/lib/render-result.js";
|
|
4
4
|
|
|
5
|
+
import { nothing } from "lit";
|
|
6
|
+
|
|
5
7
|
import { Advertising } from "./components/advertising/server.js";
|
|
6
8
|
import { BlogIndex } from "./components/blog-index/server.js";
|
|
7
9
|
import { BlogPost } from "./components/blog-post/server.js";
|
|
@@ -54,7 +56,7 @@ export async function render(path, partialContext, compilationStats) {
|
|
|
54
56
|
...(await addFluent(locale)),
|
|
55
57
|
...partialContext,
|
|
56
58
|
};
|
|
57
|
-
/** @type {import("./components/server/types.js").
|
|
59
|
+
/** @type {import("./components/server/types.js").FredLocalContents} */
|
|
58
60
|
const storageContents = {
|
|
59
61
|
componentsUsed: new Set(),
|
|
60
62
|
componentsWithStylesInHead: new Set(),
|
|
@@ -130,3 +132,33 @@ export async function render(path, partialContext, compilationStats) {
|
|
|
130
132
|
}),
|
|
131
133
|
);
|
|
132
134
|
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @param {string} path
|
|
138
|
+
* @param {import("@fred").PartialContext} partialContext
|
|
139
|
+
*/
|
|
140
|
+
export async function renderSimplified(path, partialContext) {
|
|
141
|
+
const locale = path.split("/")[1] || "en-US";
|
|
142
|
+
const context = {
|
|
143
|
+
path,
|
|
144
|
+
...(await addFluent(locale)),
|
|
145
|
+
...partialContext,
|
|
146
|
+
};
|
|
147
|
+
/** @type {import("./components/server/types.js").FredLocalContents} */
|
|
148
|
+
const storageContents = {
|
|
149
|
+
renderSimplified: true,
|
|
150
|
+
};
|
|
151
|
+
return asyncLocalStorage.run(storageContents, () =>
|
|
152
|
+
runWithContext({ locale }, async () => {
|
|
153
|
+
const component = await (async () => {
|
|
154
|
+
switch (context.renderer) {
|
|
155
|
+
case "Doc":
|
|
156
|
+
return Doc.render(context);
|
|
157
|
+
default:
|
|
158
|
+
return nothing;
|
|
159
|
+
}
|
|
160
|
+
})();
|
|
161
|
+
return await collectResult(r(component));
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
}
|