@teambit/ui 0.0.802 → 0.0.805
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/dist/create-root.js +1 -1
- package/dist/create-root.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.js.map +1 -1
- package/dist/ssr-middleware/ssr-middleware.d.ts +2 -2
- package/dist/ssr-middleware/ssr-middleware.js +20 -18
- package/dist/ssr-middleware/ssr-middleware.js.map +1 -1
- package/dist/ui-root.d.ts +3 -3
- package/dist/ui-root.js.map +1 -1
- package/dist/ui.main.runtime.d.ts +1 -1
- package/dist/ui.main.runtime.js +2 -2
- package/dist/ui.main.runtime.js.map +1 -1
- package/dist/ui.ui.runtime.d.ts +4 -5
- package/dist/ui.ui.runtime.js +27 -17
- package/dist/ui.ui.runtime.js.map +1 -1
- package/package-tar/teambit-ui-0.0.805.tgz +0 -0
- package/package.json +19 -22
- package/{preview-1659151732866.js → preview-1659456045857.js} +2 -2
- package/ssr-middleware/ssr-middleware.ts +15 -16
- package/ui-root.tsx +7 -3
- package/ui.ui.runtime.tsx +21 -18
- package/dist/react-ssr/index.d.ts +0 -5
- package/dist/react-ssr/index.js +0 -23
- package/dist/react-ssr/index.js.map +0 -1
- package/dist/react-ssr/react-ssr.d.ts +0 -21
- package/dist/react-ssr/react-ssr.js +0 -285
- package/dist/react-ssr/react-ssr.js.map +0 -1
- package/dist/react-ssr/render-lifecycle.d.ts +0 -56
- package/dist/react-ssr/render-lifecycle.js +0 -3
- package/dist/react-ssr/render-lifecycle.js.map +0 -1
- package/dist/react-ssr/request-browser.d.ts +0 -56
- package/dist/react-ssr/request-browser.js +0 -3
- package/dist/react-ssr/request-browser.js.map +0 -1
- package/dist/react-ssr/request-server.d.ts +0 -9
- package/dist/react-ssr/request-server.js +0 -3
- package/dist/react-ssr/request-server.js.map +0 -1
- package/dist/react-ssr/ssr-content.d.ts +0 -8
- package/dist/react-ssr/ssr-content.js +0 -3
- package/dist/react-ssr/ssr-content.js.map +0 -1
- package/dist/ssr-middleware/extract-browser-data.d.ts +0 -6
- package/dist/ssr-middleware/extract-browser-data.js +0 -35
- package/dist/ssr-middleware/extract-browser-data.js.map +0 -1
- package/package-tar/teambit-ui-0.0.802.tgz +0 -0
- package/react-ssr/index.ts +0 -6
- package/react-ssr/react-ssr.tsx +0 -183
- package/react-ssr/render-lifecycle.tsx +0 -58
- package/react-ssr/request-browser.ts +0 -55
- package/react-ssr/request-server.ts +0 -10
- package/react-ssr/ssr-content.ts +0 -9
- package/ssr-middleware/extract-browser-data.ts +0 -31
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["UiUI","constructor","router","uiRootSlot","hudSlot","renderPluginsSlot","element","register","render","rootExtension","rootFactory","getRoot","Error","uiRoot","routes","renderRoutes","hudItems","values","lifecyclePlugins","getLifecyclePlugins","reactSsr","
|
|
1
|
+
{"version":3,"names":["UiUI","constructor","router","uiRootSlot","hudSlot","renderPluginsSlot","element","register","render","rootExtension","rootFactory","getRoot","Error","uiRoot","routes","renderRoutes","hudItems","values","lifecyclePlugins","getLifecyclePlugins","reactSsr","BrowserRenderer","renderSsr","ssrContent","ServerRenderer","fullHtml","registerContext","context","reactContext","registerRoot","registerRenderHooks","plugin","toArray","map","key","unshift","renderPlugin","get","provider","GraphqlUi","config","renderLifecycleSlot","uiUi","renderPlugins","Slot","withType","GraphqlAspect","ReactRouterAspect","UIRuntime","UIAspect","addRuntime"],"sources":["ui.ui.runtime.tsx"],"sourcesContent":["import type { GraphqlUI } from '@teambit/graphql';\nimport { GraphqlAspect } from '@teambit/graphql';\nimport { Slot, SlotRegistry } from '@teambit/harmony';\nimport type { ReactRouterUI } from '@teambit/react-router';\nimport { ReactRouterAspect } from '@teambit/react-router';\nimport { ServerRenderer, BrowserRenderer } from '@teambit/react.rendering.ssr';\nimport type { SsrSession, RenderPlugin, ContextProps } from '@teambit/react.rendering.ssr';\n\nimport React, { ReactNode, ComponentType } from 'react';\n\nimport { UIRootFactory } from './ui-root.ui';\nimport { UIAspect, UIRuntime } from './ui.aspect';\nimport { ClientContext } from './ui/client-context';\n\ntype HudSlot = SlotRegistry<ReactNode>;\ntype RenderPluginsSlot = SlotRegistry<RenderPlugin<any, any>>;\ntype UIRootRegistry = SlotRegistry<UIRootFactory>;\n\n/**\n * extension\n */\nexport class UiUI {\n constructor(\n /**\n * react-router extension.\n */\n private router: ReactRouterUI,\n /**\n * ui root registry.\n */\n private uiRootSlot: UIRootRegistry,\n /** slot for overlay ui elements */\n private hudSlot: HudSlot,\n /** hooks into the ssr render process */\n private renderPluginsSlot: RenderPluginsSlot\n ) {}\n\n /** render and rehydrate client-side */\n async render(rootExtension: string): Promise<void> {\n const rootFactory = this.getRoot(rootExtension);\n if (!rootFactory) throw new Error(`root: ${rootExtension} was not found`);\n const uiRoot = rootFactory();\n const routes = this.router.renderRoutes(uiRoot.routes);\n const hudItems = this.hudSlot.values();\n const lifecyclePlugins = this.getLifecyclePlugins();\n\n const reactSsr = new BrowserRenderer(lifecyclePlugins);\n await reactSsr.render(\n <ClientContext>\n {hudItems}\n {routes}\n </ClientContext>\n );\n }\n\n /** render dehydrated server-side */\n async renderSsr(rootExtension: string, ssrContent: SsrSession): Promise<string> {\n const rootFactory = this.getRoot(rootExtension);\n if (!rootFactory) throw new Error(`root: ${rootExtension} was not found`);\n\n const uiRoot = rootFactory();\n const routes = this.router.renderRoutes(uiRoot.routes);\n const hudItems = this.hudSlot.values();\n const lifecyclePlugins = this.getLifecyclePlugins();\n\n const reactSsr = new ServerRenderer(lifecyclePlugins);\n const fullHtml = await reactSsr.render(\n <ClientContext>\n {hudItems}\n {routes}\n </ClientContext>,\n ssrContent\n );\n\n return fullHtml;\n }\n\n /** adds elements to the Heads Up Display */\n registerHudItem = (element: ReactNode) => {\n this.hudSlot.register(element);\n };\n\n /**\n * adds global context at the ui root\n * @deprecated replace with `.registerRenderHooks({ reactContext })`.\n */\n registerContext<T>(context: ComponentType<ContextProps<T>>) {\n this.renderPluginsSlot.register({ reactContext: context });\n }\n\n registerRoot(uiRoot: UIRootFactory) {\n return this.uiRootSlot.register(uiRoot);\n }\n\n registerRenderHooks<T, Y>(plugin: RenderPlugin<T, Y>) {\n return this.renderPluginsSlot.register(plugin);\n }\n\n private getLifecyclePlugins() {\n const lifecyclePlugins = this.renderPluginsSlot.toArray().map(([key, plugin]) => {\n if (plugin.key) return plugin;\n\n // for backward compatibility\n return { ...plugin, key };\n });\n\n // react-router should register its plugin, when we can reverse it's dependency to depend on Ui\n lifecyclePlugins.unshift(this.router.renderPlugin);\n\n return lifecyclePlugins;\n }\n\n private getRoot(rootExtension: string) {\n return this.uiRootSlot.get(rootExtension);\n }\n\n static slots = [Slot.withType<UIRootFactory>(), Slot.withType<ReactNode>(), Slot.withType<RenderPlugin>()];\n\n static dependencies = [GraphqlAspect, ReactRouterAspect];\n\n static runtime = UIRuntime;\n\n static async provider(\n [GraphqlUi, router]: [GraphqlUI, ReactRouterUI],\n config,\n [uiRootSlot, hudSlot, renderLifecycleSlot]: [UIRootRegistry, HudSlot, RenderPluginsSlot]\n ) {\n const uiUi = new UiUI(router, uiRootSlot, hudSlot, renderLifecycleSlot);\n\n if (GraphqlUi) uiUi.registerRenderHooks(GraphqlUi.renderPlugins);\n\n return uiUi;\n }\n}\n\nUIAspect.addRuntime(UiUI);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAEA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AAGA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;;;;;AAMA;AACA;AACA;AACO,MAAMA,IAAN,CAAW;EAChBC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BsC,MAFmB,EAGnB,CAACrC,UAAD,EAAaC,OAAb,EAAsBqC,mBAAtB,CAHmB,EAInB;IACA,MAAMC,IAAI,GAAG,IAAI1C,IAAJ,CAASE,MAAT,EAAiBC,UAAjB,EAA6BC,OAA7B,EAAsCqC,mBAAtC,CAAb;IAEA,IAAIF,SAAJ,EAAeG,IAAI,CAACZ,mBAAL,CAAyBS,SAAS,CAACI,aAAnC;IAEf,OAAOD,IAAP;EACD;;AA/Ge;;;gCAAL1C,I,WA+FI,CAAC4C,eAAA,CAAKC,QAAL,EAAD,EAAiCD,eAAA,CAAKC,QAAL,EAAjC,EAA6DD,eAAA,CAAKC,QAAL,EAA7D,C;gCA/FJ7C,I,kBAiGW,CAAC8C,wBAAD,EAAgBC,gCAAhB,C;gCAjGX/C,I,aAmGMgD,e;;AAenBC,cAAA,CAASC,UAAT,CAAoBlD,IAApB"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.805",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/ui-foundation/ui",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.ui-foundation",
|
|
8
8
|
"name": "ui",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.805"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -18,8 +18,6 @@
|
|
|
18
18
|
"webpack": "5.51.1",
|
|
19
19
|
"chalk": "2.4.2",
|
|
20
20
|
"fs-extra": "10.0.0",
|
|
21
|
-
"lodash.compact": "3.0.1",
|
|
22
|
-
"webpack-merge": "5.8.0",
|
|
23
21
|
"postcss-preset-env": "6.7.0",
|
|
24
22
|
"mini-css-extract-plugin": "2.2.2",
|
|
25
23
|
"webpack-manifest-plugin": "4.0.2",
|
|
@@ -27,6 +25,7 @@
|
|
|
27
25
|
"css-minimizer-webpack-plugin": "3.0.2",
|
|
28
26
|
"html-webpack-plugin": "5.3.2",
|
|
29
27
|
"terser-webpack-plugin": "5.2.0",
|
|
28
|
+
"webpack-merge": "5.8.0",
|
|
30
29
|
"@pmmmwh/react-refresh-webpack-plugin": "0.5.4",
|
|
31
30
|
"path-browserify": "1.0.1",
|
|
32
31
|
"less-loader": "8.0.0",
|
|
@@ -46,34 +45,33 @@
|
|
|
46
45
|
"source-map-loader": "3.0.0",
|
|
47
46
|
"@babel/runtime": "7.12.18",
|
|
48
47
|
"core-js": "^3.0.0",
|
|
48
|
+
"@teambit/react.rendering.ssr": "0.0.3",
|
|
49
49
|
"@teambit/harmony": "0.3.3",
|
|
50
|
-
"@teambit/base-ui.utils.composer": "1.0.0",
|
|
51
50
|
"@teambit/base-ui.loaders.loader-ribbon": "1.0.0",
|
|
52
51
|
"@teambit/base-ui.theme.fonts.roboto": "1.0.0",
|
|
53
52
|
"@teambit/base-ui.theme.theme-provider": "1.0.1",
|
|
54
|
-
"@teambit/aspect-loader": "0.0.
|
|
53
|
+
"@teambit/aspect-loader": "0.0.805",
|
|
55
54
|
"@teambit/toolbox.path.to-windows-compatible-path": "0.0.483",
|
|
56
55
|
"@teambit/ui-foundation.ui.hooks.use-data-query": "0.0.488",
|
|
57
56
|
"@teambit/bit-error": "0.0.394",
|
|
58
|
-
"@teambit/cli": "0.0.
|
|
59
|
-
"@teambit/logger": "0.0.
|
|
57
|
+
"@teambit/cli": "0.0.536",
|
|
58
|
+
"@teambit/logger": "0.0.629",
|
|
60
59
|
"@teambit/ui-foundation.cli.ui-server-console": "0.0.491",
|
|
61
|
-
"@teambit/bundler": "0.0.
|
|
62
|
-
"@teambit/component": "0.0.
|
|
63
|
-
"@teambit/express": "0.0.
|
|
64
|
-
"@teambit/graphql": "0.0.
|
|
60
|
+
"@teambit/bundler": "0.0.805",
|
|
61
|
+
"@teambit/component": "0.0.805",
|
|
62
|
+
"@teambit/express": "0.0.634",
|
|
63
|
+
"@teambit/graphql": "0.0.805",
|
|
65
64
|
"@teambit/toolbox.network.get-port": "0.0.113",
|
|
66
|
-
"@teambit/aspect": "0.0.
|
|
67
|
-
"@teambit/cache": "0.0.
|
|
68
|
-
"@teambit/pubsub": "0.0.
|
|
69
|
-
"@teambit/react-router": "0.0.
|
|
70
|
-
"@teambit/ui-foundation.ui.rendering.html": "0.0.69",
|
|
65
|
+
"@teambit/aspect": "0.0.805",
|
|
66
|
+
"@teambit/cache": "0.0.629",
|
|
67
|
+
"@teambit/pubsub": "0.0.805",
|
|
68
|
+
"@teambit/react-router": "0.0.805",
|
|
71
69
|
"@teambit/design.theme.icons-font": "2.0.8",
|
|
72
70
|
"@teambit/design.ui.tooltip": "0.0.352",
|
|
73
71
|
"@teambit/ui-foundation.ui.global-loader": "0.0.487",
|
|
74
72
|
"@teambit/webpack.modules.generate-style-loaders": "0.0.103",
|
|
75
73
|
"@teambit/webpack.modules.style-regexps": "0.0.132",
|
|
76
|
-
"@teambit/webpack": "0.0.
|
|
74
|
+
"@teambit/webpack": "0.0.805"
|
|
77
75
|
},
|
|
78
76
|
"devDependencies": {
|
|
79
77
|
"@types/lodash": "4.14.165",
|
|
@@ -83,19 +81,18 @@
|
|
|
83
81
|
"@types/express": "4.17.13",
|
|
84
82
|
"@types/webpack": "5.28.0",
|
|
85
83
|
"@types/fs-extra": "9.0.7",
|
|
86
|
-
"@types/lodash.compact": "3.0.6",
|
|
87
|
-
"@types/react-dom": "^17.0.5",
|
|
88
84
|
"@types/mini-css-extract-plugin": "2.2.0",
|
|
89
85
|
"@types/postcss-normalize": "9.0.1",
|
|
90
86
|
"@types/node": "12.20.4",
|
|
91
87
|
"@types/mocha": "9.1.0",
|
|
92
88
|
"@types/testing-library__jest-dom": "5.9.5",
|
|
93
|
-
"@types/jest": "^26.0.0"
|
|
89
|
+
"@types/jest": "^26.0.0",
|
|
90
|
+
"@types/react-dom": "^17.0.5"
|
|
94
91
|
},
|
|
95
92
|
"peerDependencies": {
|
|
96
93
|
"@apollo/client": "^3.0.0",
|
|
97
94
|
"react-router-dom": "^6.0.0",
|
|
98
|
-
"@teambit/legacy": "1.0.
|
|
95
|
+
"@teambit/legacy": "1.0.319",
|
|
99
96
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
100
97
|
"react": "^16.8.0 || ^17.0.0"
|
|
101
98
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_ui@0.0.
|
|
2
|
-
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_ui@0.0.
|
|
1
|
+
import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_ui@0.0.805/dist/ui.composition.js';
|
|
2
|
+
import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.ui-foundation_ui@0.0.805/dist/ui.docs.mdx';
|
|
3
3
|
|
|
4
4
|
export const compositions = [compositions_0];
|
|
5
5
|
export const overview = [overview_0];
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { browserFromExpress } from '@teambit/react.rendering.ssr';
|
|
2
|
+
import type { HtmlAssets, SsrSession } from '@teambit/react.rendering.ssr';
|
|
3
|
+
import type { Logger } from '@teambit/logger';
|
|
4
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
3
5
|
import path from 'path';
|
|
4
6
|
import * as fs from 'fs-extra';
|
|
5
|
-
import type { Logger } from '@teambit/logger';
|
|
6
|
-
import type { SsrContent } from '../react-ssr';
|
|
7
|
-
import { extractBrowserData } from './extract-browser-data';
|
|
8
7
|
|
|
9
8
|
const denyList = /^\/favicon.ico$/;
|
|
10
9
|
|
|
@@ -27,10 +26,10 @@ export async function createSsrMiddleware({ root, port, title, logger }: ssrRend
|
|
|
27
26
|
const { render } = runtime;
|
|
28
27
|
const assets = { ...runtime.assets, title };
|
|
29
28
|
|
|
30
|
-
return async function serverRenderMiddleware(
|
|
31
|
-
const { query, url } =
|
|
29
|
+
return async function serverRenderMiddleware(request: Request, response: Response, next: NextFunction) {
|
|
30
|
+
const { query, url } = request;
|
|
32
31
|
|
|
33
|
-
const browser =
|
|
32
|
+
const browser = browserFromExpress(request, port);
|
|
34
33
|
|
|
35
34
|
if (denyList.test(url)) {
|
|
36
35
|
logger.debug(`[ssr] skipping static denyList file ${url}`);
|
|
@@ -44,14 +43,14 @@ export async function createSsrMiddleware({ root, port, title, logger }: ssrRend
|
|
|
44
43
|
return;
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
logger.debug(`[ssr] ${
|
|
48
|
-
const server = { port, request
|
|
49
|
-
const props:
|
|
46
|
+
logger.debug(`[ssr] ${request.method} ${url}`);
|
|
47
|
+
const server = { port, request, response };
|
|
48
|
+
const props: SsrSession = { assets, browser, request, response, server };
|
|
50
49
|
|
|
51
50
|
try {
|
|
52
51
|
const rendered = await render(props);
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
response.set('Cache-Control', 'no-cache');
|
|
53
|
+
response.send(rendered);
|
|
55
54
|
logger.debug(`[ssr] success '${url}'`);
|
|
56
55
|
} catch (e: any) {
|
|
57
56
|
logger.error(`[ssr] failed at '${url}'`, e);
|
|
@@ -62,7 +61,7 @@ export async function createSsrMiddleware({ root, port, title, logger }: ssrRend
|
|
|
62
61
|
|
|
63
62
|
async function loadRuntime(root: string, { logger }: { logger: Logger }) {
|
|
64
63
|
let render: (...arg: any[]) => any;
|
|
65
|
-
let assets:
|
|
64
|
+
let assets: HtmlAssets | undefined;
|
|
66
65
|
|
|
67
66
|
try {
|
|
68
67
|
const entryFilepath = path.join(root, 'ssr', 'index.js');
|
|
@@ -84,7 +83,7 @@ async function loadRuntime(root: string, { logger }: { logger: Logger }) {
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
const imported = await import(entryFilepath);
|
|
87
|
-
render = imported?.render;
|
|
86
|
+
render = imported?.default || imported?.render;
|
|
88
87
|
|
|
89
88
|
if (!render || typeof render !== 'function') {
|
|
90
89
|
logger.warn('[ssr] - index file does not export a render() function. Skipping setup.');
|
|
@@ -120,7 +119,7 @@ async function parseManifest(filepath: string, logger?: Logger) {
|
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
function getAssets(manifest: ManifestFile) {
|
|
123
|
-
const assets:
|
|
122
|
+
const assets: HtmlAssets = { css: [], js: [] };
|
|
124
123
|
|
|
125
124
|
assets.css = manifest.entrypoints?.filter((x) => x.endsWith('css')).map((x) => path.join('/', x));
|
|
126
125
|
assets.js = manifest.entrypoints?.filter((x) => x.endsWith('js')).map((x) => path.join('/', x));
|
package/ui-root.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AspectDefinition } from '@teambit/aspect-loader';
|
|
2
2
|
import { ComponentDir } from '@teambit/bundler';
|
|
3
|
-
import { Component } from '@teambit/component';
|
|
3
|
+
import { Component, ComponentID, ResolveAspectsOptions } from '@teambit/component';
|
|
4
4
|
import { ProxyConfigArrayItem } from 'webpack-dev-server';
|
|
5
5
|
|
|
6
6
|
// TODO: remove this extends "ComponentDir", this should be part of the workspace alone since scope
|
|
@@ -27,9 +27,13 @@ export interface UIRoot extends ComponentDir {
|
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* resolve
|
|
30
|
+
* resolve aspects in the UI root. (resolve all if componentIds not provided)
|
|
31
31
|
*/
|
|
32
|
-
resolveAspects(
|
|
32
|
+
resolveAspects(
|
|
33
|
+
runtimeName: string,
|
|
34
|
+
componentIds?: ComponentID[],
|
|
35
|
+
opts?: ResolveAspectsOptions
|
|
36
|
+
): Promise<AspectDefinition[]>;
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* resolve components from a given pattern.
|
package/ui.ui.runtime.tsx
CHANGED
|
@@ -3,18 +3,17 @@ import { GraphqlAspect } from '@teambit/graphql';
|
|
|
3
3
|
import { Slot, SlotRegistry } from '@teambit/harmony';
|
|
4
4
|
import type { ReactRouterUI } from '@teambit/react-router';
|
|
5
5
|
import { ReactRouterAspect } from '@teambit/react-router';
|
|
6
|
+
import { ServerRenderer, BrowserRenderer } from '@teambit/react.rendering.ssr';
|
|
7
|
+
import type { SsrSession, RenderPlugin, ContextProps } from '@teambit/react.rendering.ssr';
|
|
6
8
|
|
|
7
9
|
import React, { ReactNode, ComponentType } from 'react';
|
|
8
10
|
|
|
9
11
|
import { UIRootFactory } from './ui-root.ui';
|
|
10
12
|
import { UIAspect, UIRuntime } from './ui.aspect';
|
|
11
13
|
import { ClientContext } from './ui/client-context';
|
|
12
|
-
import type { SsrContent } from './react-ssr/ssr-content';
|
|
13
|
-
import { ContextProps, RenderPlugins } from './react-ssr/render-lifecycle';
|
|
14
|
-
import { ReactSSR } from './react-ssr/react-ssr';
|
|
15
14
|
|
|
16
15
|
type HudSlot = SlotRegistry<ReactNode>;
|
|
17
|
-
type RenderPluginsSlot = SlotRegistry<
|
|
16
|
+
type RenderPluginsSlot = SlotRegistry<RenderPlugin<any, any>>;
|
|
18
17
|
type UIRootRegistry = SlotRegistry<UIRootFactory>;
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -45,8 +44,8 @@ export class UiUI {
|
|
|
45
44
|
const hudItems = this.hudSlot.values();
|
|
46
45
|
const lifecyclePlugins = this.getLifecyclePlugins();
|
|
47
46
|
|
|
48
|
-
const reactSsr = new
|
|
49
|
-
await reactSsr.
|
|
47
|
+
const reactSsr = new BrowserRenderer(lifecyclePlugins);
|
|
48
|
+
await reactSsr.render(
|
|
50
49
|
<ClientContext>
|
|
51
50
|
{hudItems}
|
|
52
51
|
{routes}
|
|
@@ -55,7 +54,7 @@ export class UiUI {
|
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
/** render dehydrated server-side */
|
|
58
|
-
async renderSsr(rootExtension: string, ssrContent:
|
|
57
|
+
async renderSsr(rootExtension: string, ssrContent: SsrSession): Promise<string> {
|
|
59
58
|
const rootFactory = this.getRoot(rootExtension);
|
|
60
59
|
if (!rootFactory) throw new Error(`root: ${rootExtension} was not found`);
|
|
61
60
|
|
|
@@ -64,8 +63,8 @@ export class UiUI {
|
|
|
64
63
|
const hudItems = this.hudSlot.values();
|
|
65
64
|
const lifecyclePlugins = this.getLifecyclePlugins();
|
|
66
65
|
|
|
67
|
-
const reactSsr = new
|
|
68
|
-
const fullHtml = await reactSsr.
|
|
66
|
+
const reactSsr = new ServerRenderer(lifecyclePlugins);
|
|
67
|
+
const fullHtml = await reactSsr.render(
|
|
69
68
|
<ClientContext>
|
|
70
69
|
{hudItems}
|
|
71
70
|
{routes}
|
|
@@ -86,23 +85,27 @@ export class UiUI {
|
|
|
86
85
|
* @deprecated replace with `.registerRenderHooks({ reactContext })`.
|
|
87
86
|
*/
|
|
88
87
|
registerContext<T>(context: ComponentType<ContextProps<T>>) {
|
|
89
|
-
this.renderPluginsSlot.register({
|
|
90
|
-
reactContext: context,
|
|
91
|
-
});
|
|
88
|
+
this.renderPluginsSlot.register({ reactContext: context });
|
|
92
89
|
}
|
|
93
90
|
|
|
94
91
|
registerRoot(uiRoot: UIRootFactory) {
|
|
95
92
|
return this.uiRootSlot.register(uiRoot);
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
registerRenderHooks<T, Y>(
|
|
99
|
-
return this.renderPluginsSlot.register(
|
|
95
|
+
registerRenderHooks<T, Y>(plugin: RenderPlugin<T, Y>) {
|
|
96
|
+
return this.renderPluginsSlot.register(plugin);
|
|
100
97
|
}
|
|
101
98
|
|
|
102
99
|
private getLifecyclePlugins() {
|
|
103
|
-
const lifecyclePlugins = this.renderPluginsSlot.toArray()
|
|
100
|
+
const lifecyclePlugins = this.renderPluginsSlot.toArray().map(([key, plugin]) => {
|
|
101
|
+
if (plugin.key) return plugin;
|
|
102
|
+
|
|
103
|
+
// for backward compatibility
|
|
104
|
+
return { ...plugin, key };
|
|
105
|
+
});
|
|
106
|
+
|
|
104
107
|
// react-router should register its plugin, when we can reverse it's dependency to depend on Ui
|
|
105
|
-
lifecyclePlugins.unshift(
|
|
108
|
+
lifecyclePlugins.unshift(this.router.renderPlugin);
|
|
106
109
|
|
|
107
110
|
return lifecyclePlugins;
|
|
108
111
|
}
|
|
@@ -111,7 +114,7 @@ export class UiUI {
|
|
|
111
114
|
return this.uiRootSlot.get(rootExtension);
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
static slots = [Slot.withType<UIRootFactory>(), Slot.withType<ReactNode>(), Slot.withType<
|
|
117
|
+
static slots = [Slot.withType<UIRootFactory>(), Slot.withType<ReactNode>(), Slot.withType<RenderPlugin>()];
|
|
115
118
|
|
|
116
119
|
static dependencies = [GraphqlAspect, ReactRouterAspect];
|
|
117
120
|
|
|
@@ -124,7 +127,7 @@ export class UiUI {
|
|
|
124
127
|
) {
|
|
125
128
|
const uiUi = new UiUI(router, uiRootSlot, hudSlot, renderLifecycleSlot);
|
|
126
129
|
|
|
127
|
-
uiUi.registerRenderHooks(GraphqlUi.renderPlugins);
|
|
130
|
+
if (GraphqlUi) uiUi.registerRenderHooks(GraphqlUi.renderPlugins);
|
|
128
131
|
|
|
129
132
|
return uiUi;
|
|
130
133
|
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { ReactSSR } from './react-ssr';
|
|
2
|
-
export type { ContextProps, RenderPlugins } from './render-lifecycle';
|
|
3
|
-
export type { BrowserData, ParsedQuery } from './request-browser';
|
|
4
|
-
export type { RequestServer } from './request-server';
|
|
5
|
-
export type { SsrContent } from './ssr-content';
|
package/dist/react-ssr/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "ReactSSR", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _reactSsr().ReactSSR;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
function _reactSsr() {
|
|
14
|
-
const data = require("./react-ssr");
|
|
15
|
-
|
|
16
|
-
_reactSsr = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export { ReactSSR } from './react-ssr';\n\nexport type { ContextProps, RenderPlugins } from './render-lifecycle';\nexport type { BrowserData, ParsedQuery } from './request-browser';\nexport type { RequestServer } from './request-server';\nexport type { SsrContent } from './ssr-content';\n"],"mappings":";;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import type { RenderPlugins } from './render-lifecycle';
|
|
3
|
-
import type { SsrContent } from './ssr-content';
|
|
4
|
-
declare type RenderPluginsWithId = [key: string, hooks: RenderPlugins];
|
|
5
|
-
export declare class ReactSSR {
|
|
6
|
-
private lifecycleHooks;
|
|
7
|
-
constructor(lifecycleHooks: RenderPluginsWithId[]);
|
|
8
|
-
/** render and rehydrate client-side */
|
|
9
|
-
renderBrowser(children: ReactNode): Promise<void>;
|
|
10
|
-
/** render dehydrated server-side */
|
|
11
|
-
renderServer(children: ReactNode, { assets, browser, server }?: SsrContent): Promise<string>;
|
|
12
|
-
private triggerBrowserInit;
|
|
13
|
-
private triggerServerInit;
|
|
14
|
-
private triggerBeforeHydrateHook;
|
|
15
|
-
private triggerHydrateHook;
|
|
16
|
-
private triggerBeforeRender;
|
|
17
|
-
private getReactContexts;
|
|
18
|
-
private deserialize;
|
|
19
|
-
private serialize;
|
|
20
|
-
}
|
|
21
|
-
export {};
|