@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.
Files changed (50) hide show
  1. package/dist/create-root.js +1 -1
  2. package/dist/create-root.js.map +1 -1
  3. package/dist/index.d.ts +12 -5
  4. package/dist/index.js.map +1 -1
  5. package/dist/ssr-middleware/ssr-middleware.d.ts +2 -2
  6. package/dist/ssr-middleware/ssr-middleware.js +20 -18
  7. package/dist/ssr-middleware/ssr-middleware.js.map +1 -1
  8. package/dist/ui-root.d.ts +3 -3
  9. package/dist/ui-root.js.map +1 -1
  10. package/dist/ui.main.runtime.d.ts +1 -1
  11. package/dist/ui.main.runtime.js +2 -2
  12. package/dist/ui.main.runtime.js.map +1 -1
  13. package/dist/ui.ui.runtime.d.ts +4 -5
  14. package/dist/ui.ui.runtime.js +27 -17
  15. package/dist/ui.ui.runtime.js.map +1 -1
  16. package/package-tar/teambit-ui-0.0.805.tgz +0 -0
  17. package/package.json +19 -22
  18. package/{preview-1659151732866.js → preview-1659456045857.js} +2 -2
  19. package/ssr-middleware/ssr-middleware.ts +15 -16
  20. package/ui-root.tsx +7 -3
  21. package/ui.ui.runtime.tsx +21 -18
  22. package/dist/react-ssr/index.d.ts +0 -5
  23. package/dist/react-ssr/index.js +0 -23
  24. package/dist/react-ssr/index.js.map +0 -1
  25. package/dist/react-ssr/react-ssr.d.ts +0 -21
  26. package/dist/react-ssr/react-ssr.js +0 -285
  27. package/dist/react-ssr/react-ssr.js.map +0 -1
  28. package/dist/react-ssr/render-lifecycle.d.ts +0 -56
  29. package/dist/react-ssr/render-lifecycle.js +0 -3
  30. package/dist/react-ssr/render-lifecycle.js.map +0 -1
  31. package/dist/react-ssr/request-browser.d.ts +0 -56
  32. package/dist/react-ssr/request-browser.js +0 -3
  33. package/dist/react-ssr/request-browser.js.map +0 -1
  34. package/dist/react-ssr/request-server.d.ts +0 -9
  35. package/dist/react-ssr/request-server.js +0 -3
  36. package/dist/react-ssr/request-server.js.map +0 -1
  37. package/dist/react-ssr/ssr-content.d.ts +0 -8
  38. package/dist/react-ssr/ssr-content.js +0 -3
  39. package/dist/react-ssr/ssr-content.js.map +0 -1
  40. package/dist/ssr-middleware/extract-browser-data.d.ts +0 -6
  41. package/dist/ssr-middleware/extract-browser-data.js +0 -35
  42. package/dist/ssr-middleware/extract-browser-data.js.map +0 -1
  43. package/package-tar/teambit-ui-0.0.802.tgz +0 -0
  44. package/react-ssr/index.ts +0 -6
  45. package/react-ssr/react-ssr.tsx +0 -183
  46. package/react-ssr/render-lifecycle.tsx +0 -58
  47. package/react-ssr/request-browser.ts +0 -55
  48. package/react-ssr/request-server.ts +0 -10
  49. package/react-ssr/ssr-content.ts +0 -9
  50. package/ssr-middleware/extract-browser-data.ts +0 -31
@@ -1,285 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- require("core-js/modules/es.array.iterator.js");
6
-
7
- require("core-js/modules/es.promise.js");
8
-
9
- Object.defineProperty(exports, "__esModule", {
10
- value: true
11
- });
12
- exports.ReactSSR = void 0;
13
-
14
- function _react() {
15
- const data = _interopRequireDefault(require("react"));
16
-
17
- _react = function () {
18
- return data;
19
- };
20
-
21
- return data;
22
- }
23
-
24
- function _webpackMerge() {
25
- const data = require("webpack-merge");
26
-
27
- _webpackMerge = function () {
28
- return data;
29
- };
30
-
31
- return data;
32
- }
33
-
34
- function _lodash() {
35
- const data = _interopRequireDefault(require("lodash.compact"));
36
-
37
- _lodash = function () {
38
- return data;
39
- };
40
-
41
- return data;
42
- }
43
-
44
- function _reactDom() {
45
- const data = _interopRequireDefault(require("react-dom"));
46
-
47
- _reactDom = function () {
48
- return data;
49
- };
50
-
51
- return data;
52
- }
53
-
54
- function _server() {
55
- const data = _interopRequireDefault(require("react-dom/server"));
56
-
57
- _server = function () {
58
- return data;
59
- };
60
-
61
- return data;
62
- }
63
-
64
- function _uiFoundationUiRendering() {
65
- const data = require("@teambit/ui-foundation.ui.rendering.html");
66
-
67
- _uiFoundationUiRendering = function () {
68
- return data;
69
- };
70
-
71
- return data;
72
- }
73
-
74
- function _baseUiUtils() {
75
- const data = require("@teambit/base-ui.utils.composer");
76
-
77
- _baseUiUtils = function () {
78
- return data;
79
- };
80
-
81
- return data;
82
- }
83
-
84
- class ReactSSR {
85
- constructor( // create array once to keep consistent indexes
86
- lifecycleHooks) {
87
- this.lifecycleHooks = lifecycleHooks;
88
- }
89
- /** render and rehydrate client-side */
90
-
91
-
92
- async renderBrowser(children) {
93
- // (*) load state from the dom
94
- const deserializedState = await this.deserialize(); // (1) init setup client plugins
95
-
96
- let renderContexts = await this.triggerBrowserInit(deserializedState); // (2) make react dom
97
-
98
- const reactContexts = this.getReactContexts(renderContexts);
99
-
100
- const app = /*#__PURE__*/_react().default.createElement(_baseUiUtils().Composer, {
101
- components: reactContexts
102
- }, children);
103
-
104
- renderContexts = await this.triggerBeforeHydrateHook(renderContexts, app); // (3) render / rehydrate
105
-
106
- const mountPoint = document.getElementById(_uiFoundationUiRendering().mountPointId); // .render() already runs `.hydrate()` behind the scenes.
107
- // in the future, we may want to replace it with .hydrate()
108
-
109
- _reactDom().default.render(app, mountPoint);
110
-
111
- await this.triggerHydrateHook(renderContexts, mountPoint); // (3.1) remove ssr only styles
112
-
113
- (0, _uiFoundationUiRendering().ssrCleanup)();
114
- }
115
- /** render dehydrated server-side */
116
-
117
-
118
- async renderServer(children, {
119
- assets,
120
- browser,
121
- server
122
- } = {}) {
123
- // (1) init
124
- let renderContexts = await this.triggerServerInit(browser, server); // (2) make React dom
125
-
126
- const reactContexts = this.getReactContexts(renderContexts);
127
-
128
- const app = /*#__PURE__*/_react().default.createElement(_uiFoundationUiRendering().MountPoint, null, /*#__PURE__*/_react().default.createElement(_baseUiUtils().Composer, {
129
- components: reactContexts
130
- }, children));
131
-
132
- renderContexts = await this.triggerBeforeRender(renderContexts, app); // (3) render (to string)
133
-
134
- const renderedApp = _server().default.renderToString(app); // (*) serialize state
135
-
136
-
137
- const realtimeAssets = await this.serialize(renderContexts, app); // @ts-ignore // TODO upgrade 'webpack-merge'
138
-
139
- const totalAssets = (0, _webpackMerge().merge)(assets, realtimeAssets); // (4) render html-template (to string)
140
-
141
- const html = /*#__PURE__*/_react().default.createElement(_uiFoundationUiRendering().Html, {
142
- assets: totalAssets,
143
- withDevTools: true,
144
- fullHeight: true,
145
- ssr: true
146
- });
147
-
148
- const renderedHtml = `<!DOCTYPE html>${_server().default.renderToStaticMarkup(html)}`;
149
-
150
- const fullHtml = _uiFoundationUiRendering().Html.fillContent(renderedHtml, renderedApp); // (5) serve
151
-
152
-
153
- return fullHtml;
154
- }
155
-
156
- triggerBrowserInit(deserializedState) {
157
- const {
158
- lifecycleHooks
159
- } = this;
160
- const initPromises = lifecycleHooks.map(([, hooks], idx) => {
161
- var _hooks$browserInit;
162
-
163
- const state = deserializedState[idx];
164
- return (_hooks$browserInit = hooks.browserInit) === null || _hooks$browserInit === void 0 ? void 0 : _hooks$browserInit.call(hooks, state);
165
- });
166
- return Promise.all(initPromises);
167
- }
168
-
169
- triggerServerInit(browser, server) {
170
- const {
171
- lifecycleHooks
172
- } = this;
173
- const promises = lifecycleHooks.map(([, hooks]) => {
174
- var _hooks$serverInit;
175
-
176
- return (_hooks$serverInit = hooks.serverInit) === null || _hooks$serverInit === void 0 ? void 0 : _hooks$serverInit.call(hooks, {
177
- browser,
178
- server
179
- });
180
- });
181
- return Promise.all(promises);
182
- }
183
-
184
- triggerBeforeHydrateHook(renderContexts, app) {
185
- const {
186
- lifecycleHooks
187
- } = this;
188
- const promises = lifecycleHooks.map(async ([, hooks], idx) => {
189
- var _hooks$onBeforeHydrat;
190
-
191
- const ctx = renderContexts[idx];
192
- const nextCtx = await ((_hooks$onBeforeHydrat = hooks.onBeforeHydrate) === null || _hooks$onBeforeHydrat === void 0 ? void 0 : _hooks$onBeforeHydrat.call(hooks, ctx, app));
193
- return nextCtx || ctx;
194
- });
195
- return Promise.all(promises);
196
- }
197
-
198
- async triggerHydrateHook(renderContexts, mountPoint) {
199
- const {
200
- lifecycleHooks
201
- } = this;
202
- const promises = lifecycleHooks.map(([, hooks], idx) => {
203
- var _hooks$onHydrate;
204
-
205
- const renderCtx = renderContexts[idx];
206
- return (_hooks$onHydrate = hooks.onHydrate) === null || _hooks$onHydrate === void 0 ? void 0 : _hooks$onHydrate.call(hooks, renderCtx, mountPoint);
207
- });
208
- await Promise.all(promises);
209
- }
210
-
211
- async triggerBeforeRender(renderContexts, app) {
212
- const {
213
- lifecycleHooks
214
- } = this;
215
- const promises = lifecycleHooks.map(async ([, hooks], idx) => {
216
- var _hooks$onBeforeRender;
217
-
218
- const ctx = renderContexts[idx];
219
- const nextCtx = await ((_hooks$onBeforeRender = hooks.onBeforeRender) === null || _hooks$onBeforeRender === void 0 ? void 0 : _hooks$onBeforeRender.call(hooks, ctx, app));
220
- return nextCtx || ctx;
221
- });
222
- await Promise.all(promises);
223
- return renderContexts;
224
- }
225
-
226
- getReactContexts(renderContexts) {
227
- const {
228
- lifecycleHooks
229
- } = this;
230
- return (0, _lodash().default)(lifecycleHooks.map(([, hooks], idx) => {
231
- const renderCtx = renderContexts[idx];
232
- const props = {
233
- renderCtx
234
- };
235
- return hooks.reactContext ? [hooks.reactContext, props] : undefined;
236
- }));
237
- }
238
-
239
- async deserialize() {
240
- const {
241
- lifecycleHooks
242
- } = this;
243
-
244
- const rawAssets = _uiFoundationUiRendering().Html.popAssets();
245
-
246
- const deserialized = await Promise.all(lifecycleHooks.map(async ([key, hooks]) => {
247
- try {
248
- var _hooks$deserialize;
249
-
250
- const raw = rawAssets.get(key);
251
- return (_hooks$deserialize = hooks.deserialize) === null || _hooks$deserialize === void 0 ? void 0 : _hooks$deserialize.call(hooks, raw);
252
- } catch (e) {
253
- // eslint-disable-next-line no-console
254
- console.error(`failed deserializing server state for aspect ${key}`, e);
255
- return undefined;
256
- }
257
- }));
258
- return deserialized;
259
- }
260
-
261
- async serialize(renderContexts, app) {
262
- const {
263
- lifecycleHooks
264
- } = this;
265
- const json = {};
266
- const promises = lifecycleHooks.map(async ([key, hooks], idx) => {
267
- var _hooks$serialize;
268
-
269
- const renderCtx = renderContexts[idx];
270
- const result = await ((_hooks$serialize = hooks.serialize) === null || _hooks$serialize === void 0 ? void 0 : _hooks$serialize.call(hooks, renderCtx, app));
271
- if (!result) return;
272
- if (result.json) json[key] = result.json;
273
- });
274
- await Promise.all(promises); // more assets will be available in the future
275
-
276
- return {
277
- json
278
- };
279
- }
280
-
281
- }
282
-
283
- exports.ReactSSR = ReactSSR;
284
-
285
- //# sourceMappingURL=react-ssr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["ReactSSR","constructor","lifecycleHooks","renderBrowser","children","deserializedState","deserialize","renderContexts","triggerBrowserInit","reactContexts","getReactContexts","app","triggerBeforeHydrateHook","mountPoint","document","getElementById","mountPointId","ReactDOM","render","triggerHydrateHook","ssrCleanup","renderServer","assets","browser","server","triggerServerInit","triggerBeforeRender","renderedApp","ReactDOMServer","renderToString","realtimeAssets","serialize","totalAssets","merge","html","renderedHtml","renderToStaticMarkup","fullHtml","Html","fillContent","initPromises","map","hooks","idx","state","browserInit","Promise","all","promises","serverInit","ctx","nextCtx","onBeforeHydrate","renderCtx","onHydrate","onBeforeRender","compact","props","reactContext","undefined","rawAssets","popAssets","deserialized","key","raw","get","e","console","error","json","result"],"sources":["react-ssr.tsx"],"sourcesContent":["import React, { ReactNode } from 'react';\nimport { merge } from 'webpack-merge';\nimport compact from 'lodash.compact';\nimport ReactDOM from 'react-dom';\nimport ReactDOMServer from 'react-dom/server';\n\nimport { Html, MountPoint, mountPointId, ssrCleanup, Assets } from '@teambit/ui-foundation.ui.rendering.html';\nimport { Composer, Wrapper } from '@teambit/base-ui.utils.composer';\n\nimport type { RenderPlugins } from './render-lifecycle';\nimport type { SsrContent } from './ssr-content';\nimport type { RequestServer } from './request-server';\nimport type { BrowserData } from './request-browser';\n\ntype RenderPluginsWithId = [key: string, hooks: RenderPlugins];\n\nexport class ReactSSR {\n constructor(\n // create array once to keep consistent indexes\n private lifecycleHooks: RenderPluginsWithId[]\n ) {}\n\n /** render and rehydrate client-side */\n async renderBrowser(children: ReactNode) {\n // (*) load state from the dom\n const deserializedState = await this.deserialize();\n\n // (1) init setup client plugins\n let renderContexts = await this.triggerBrowserInit(deserializedState);\n\n // (2) make react dom\n const reactContexts = this.getReactContexts(renderContexts);\n const app = <Composer components={reactContexts}>{children}</Composer>;\n\n renderContexts = await this.triggerBeforeHydrateHook(renderContexts, app);\n\n // (3) render / rehydrate\n const mountPoint = document.getElementById(mountPointId);\n // .render() already runs `.hydrate()` behind the scenes.\n // in the future, we may want to replace it with .hydrate()\n ReactDOM.render(app, mountPoint);\n\n await this.triggerHydrateHook(renderContexts, mountPoint);\n\n // (3.1) remove ssr only styles\n ssrCleanup();\n }\n\n /** render dehydrated server-side */\n async renderServer(children: ReactNode, { assets, browser, server }: SsrContent = {}): Promise<string> {\n // (1) init\n let renderContexts = await this.triggerServerInit(browser, server);\n\n // (2) make React dom\n const reactContexts = this.getReactContexts(renderContexts);\n const app = (\n <MountPoint>\n <Composer components={reactContexts}>{children}</Composer>\n </MountPoint>\n );\n\n renderContexts = await this.triggerBeforeRender(renderContexts, app);\n\n // (3) render (to string)\n const renderedApp = ReactDOMServer.renderToString(app);\n\n // (*) serialize state\n const realtimeAssets = await this.serialize(renderContexts, app);\n // @ts-ignore // TODO upgrade 'webpack-merge'\n const totalAssets = merge(assets, realtimeAssets) as Assets;\n\n // (4) render html-template (to string)\n const html = <Html assets={totalAssets} withDevTools fullHeight ssr />;\n const renderedHtml = `<!DOCTYPE html>${ReactDOMServer.renderToStaticMarkup(html)}`;\n const fullHtml = Html.fillContent(renderedHtml, renderedApp);\n\n // (5) serve\n return fullHtml;\n }\n\n private triggerBrowserInit(deserializedState: any[]) {\n const { lifecycleHooks } = this;\n\n const initPromises = lifecycleHooks.map(([, hooks], idx) => {\n const state = deserializedState[idx];\n return hooks.browserInit?.(state);\n });\n return Promise.all(initPromises);\n }\n\n private triggerServerInit(browser?: BrowserData, server?: RequestServer) {\n const { lifecycleHooks } = this;\n const promises = lifecycleHooks.map(([, hooks]) => hooks.serverInit?.({ browser, server }));\n return Promise.all(promises);\n }\n\n private triggerBeforeHydrateHook(renderContexts: any[], app: JSX.Element) {\n const { lifecycleHooks } = this;\n\n const promises = lifecycleHooks.map(async ([, hooks], idx) => {\n const ctx = renderContexts[idx];\n const nextCtx = await hooks.onBeforeHydrate?.(ctx, app);\n return nextCtx || ctx;\n });\n\n return Promise.all(promises);\n }\n\n private async triggerHydrateHook(renderContexts: any[], mountPoint: HTMLElement | null) {\n const { lifecycleHooks } = this;\n\n const promises = lifecycleHooks.map(([, hooks], idx) => {\n const renderCtx = renderContexts[idx];\n return hooks.onHydrate?.(renderCtx, mountPoint);\n });\n\n await Promise.all(promises);\n }\n\n private async triggerBeforeRender(renderContexts: any[], app: JSX.Element) {\n const { lifecycleHooks } = this;\n\n const promises = lifecycleHooks.map(async ([, hooks], idx) => {\n const ctx = renderContexts[idx];\n const nextCtx = await hooks.onBeforeRender?.(ctx, app);\n return nextCtx || ctx;\n });\n\n await Promise.all(promises);\n\n return renderContexts;\n }\n\n private getReactContexts(renderContexts: any[]): Wrapper[] {\n const { lifecycleHooks } = this;\n\n return compact(\n lifecycleHooks.map(([, hooks], idx) => {\n const renderCtx = renderContexts[idx];\n const props = { renderCtx };\n return hooks.reactContext ? [hooks.reactContext, props] : undefined;\n })\n );\n }\n\n private async deserialize() {\n const { lifecycleHooks } = this;\n const rawAssets = Html.popAssets();\n\n const deserialized = await Promise.all(\n lifecycleHooks.map(async ([key, hooks]) => {\n try {\n const raw = rawAssets.get(key);\n return hooks.deserialize?.(raw);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(`failed deserializing server state for aspect ${key}`, e);\n return undefined;\n }\n })\n );\n\n return deserialized;\n }\n\n private async serialize(renderContexts: any[], app: ReactNode): Promise<Assets> {\n const { lifecycleHooks } = this;\n const json = {};\n\n const promises = lifecycleHooks.map(async ([key, hooks], idx) => {\n const renderCtx = renderContexts[idx];\n const result = await hooks.serialize?.(renderCtx, app);\n\n if (!result) return;\n if (result.json) json[key] = result.json;\n });\n\n await Promise.all(promises);\n\n // more assets will be available in the future\n return { json };\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;AACA;EAAA;;EAAA;IAAA;EAAA;;EAAA;AAAA;;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;;AASO,MAAMA,QAAN,CAAe;EACpBC,WAAW,EACT;EACQC,cAFC,EAGT;IAAA,KADQA,cACR,GADQA,cACR;EAAE;EAEJ;;;EACmB,MAAbC,aAAa,CAACC,QAAD,EAAsB;IACvC;IACA,MAAMC,iBAAiB,GAAG,MAAM,KAAKC,WAAL,EAAhC,CAFuC,CAIvC;;IACA,IAAIC,cAAc,GAAG,MAAM,KAAKC,kBAAL,CAAwBH,iBAAxB,CAA3B,CALuC,CAOvC;;IACA,MAAMI,aAAa,GAAG,KAAKC,gBAAL,CAAsBH,cAAtB,CAAtB;;IACA,MAAMI,GAAG,gBAAG,+BAAC,uBAAD;MAAU,UAAU,EAAEF;IAAtB,GAAsCL,QAAtC,CAAZ;;IAEAG,cAAc,GAAG,MAAM,KAAKK,wBAAL,CAA8BL,cAA9B,EAA8CI,GAA9C,CAAvB,CAXuC,CAavC;;IACA,MAAME,UAAU,GAAGC,QAAQ,CAACC,cAAT,CAAwBC,uCAAxB,CAAnB,CAduC,CAevC;IACA;;IACAC,mBAAA,CAASC,MAAT,CAAgBP,GAAhB,EAAqBE,UAAr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EAAiBA,IAAI,CAACN,GAAD,CAAJ,GAAYO,MAAM,CAACD,IAAnB;IAClB,CANgB,CAAjB;IAQA,MAAMvB,OAAO,CAACC,GAAR,CAAYC,QAAZ,CAAN,CAZ8E,CAc9E;;IACA,OAAO;MAAEqB;IAAF,CAAP;EACD;;AArKmB"}
@@ -1,56 +0,0 @@
1
- import { ReactNode, ComponentType } from 'react';
2
- import { BrowserData } from './request-browser';
3
- import { RequestServer } from './request-server';
4
- export declare type ContextProps<T = any> = {
5
- renderCtx?: T;
6
- children: ReactNode;
7
- };
8
- /** Plugins for each step of the SSR and regular rendering lifecycle */
9
- export declare type RenderPlugins<RenderCtx = any, Serialized = any> = {
10
- /**
11
- * Initialize a context state for this specific rendering.
12
- * Context state will only be available to the current Aspect, in the other hooks, as well as a prop to the react context component.
13
- */
14
- serverInit?: (state: {
15
- browser?: BrowserData;
16
- server?: RequestServer;
17
- }) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;
18
- /**
19
- * Executes before running ReactDOM.renderToString(). Return value will replace the existing context state.
20
- */
21
- onBeforeRender?: (ctx: RenderCtx, app: ReactNode) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;
22
- /**
23
- * Produce html assets. Runs after the body is rendered, and before rendering the final html.
24
- * @returns
25
- * json: will be rendered to the dom as a `<script type="json"/>`.
26
- * More assets will be available in the future.
27
- */
28
- serialize?: (ctx: RenderCtx, app: ReactNode) => {
29
- json: string;
30
- } | Promise<{
31
- json: string;
32
- }> | undefined;
33
- /**
34
- * Converts serialized data from raw string back to structured data.
35
- * @example deserialize: (data) => { const parsed = JSON.parse(data); return { analytics: new AnalyticsService(parsed); } }
36
- */
37
- deserialize?: (data?: string) => Serialized;
38
- /**
39
- * Initialize the context state for client side rendering.
40
- * Context state will only be available to the current Aspect, in the other hooks, as well as a prop to the react context component.
41
- */
42
- browserInit?: (deserializedData: Serialized) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;
43
- /**
44
- * Executes before running ReactDOM.hydrate() (or .render() in case server side rendering is skipped). Receives the context produced by `deserialize()`
45
- */
46
- onBeforeHydrate?: (context: RenderCtx, app: ReactNode) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;
47
- /**
48
- * Executes after browser rendering is complete. Receives context from the previous steps.
49
- * @example onHydrate: (ref, { analytics }) => { analytics.reportPageView() }
50
- */
51
- onHydrate?: (context: RenderCtx, ref: HTMLElement | null) => void;
52
- /**
53
- * Wraps dom with a context. Will receive render context, produced by `onBeforeRender()` (at server-side) or `deserialize()` (at the browser)
54
- */
55
- reactContext?: ComponentType<ContextProps<RenderCtx>>;
56
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- //# sourceMappingURL=render-lifecycle.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["render-lifecycle.tsx"],"sourcesContent":["import { ReactNode, ComponentType } from 'react';\nimport { BrowserData } from './request-browser';\nimport { RequestServer } from './request-server';\n\nexport type ContextProps<T = any> = { renderCtx?: T; children: ReactNode };\n\n/** Plugins for each step of the SSR and regular rendering lifecycle */\nexport type RenderPlugins<RenderCtx = any, Serialized = any> = {\n /**\n * Initialize a context state for this specific rendering.\n * Context state will only be available to the current Aspect, in the other hooks, as well as a prop to the react context component.\n */\n serverInit?: (state: {\n browser?: BrowserData;\n server?: RequestServer;\n }) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;\n /**\n * Executes before running ReactDOM.renderToString(). Return value will replace the existing context state.\n */\n onBeforeRender?: (\n ctx: RenderCtx,\n app: ReactNode\n ) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;\n /**\n * Produce html assets. Runs after the body is rendered, and before rendering the final html.\n * @returns\n * json: will be rendered to the dom as a `<script type=\"json\"/>`.\n * More assets will be available in the future.\n */\n serialize?: (ctx: RenderCtx, app: ReactNode) => { json: string } | Promise<{ json: string }> | undefined;\n /**\n * Converts serialized data from raw string back to structured data.\n * @example deserialize: (data) => { const parsed = JSON.parse(data); return { analytics: new AnalyticsService(parsed); } }\n */\n deserialize?: (data?: string) => Serialized;\n /**\n * Initialize the context state for client side rendering.\n * Context state will only be available to the current Aspect, in the other hooks, as well as a prop to the react context component.\n */\n browserInit?: (deserializedData: Serialized) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;\n /**\n * Executes before running ReactDOM.hydrate() (or .render() in case server side rendering is skipped). Receives the context produced by `deserialize()`\n */\n onBeforeHydrate?: (\n context: RenderCtx,\n app: ReactNode\n ) => RenderCtx | void | undefined | Promise<RenderCtx | void | undefined>;\n /**\n * Executes after browser rendering is complete. Receives context from the previous steps.\n * @example onHydrate: (ref, { analytics }) => { analytics.reportPageView() }\n */\n onHydrate?: (context: RenderCtx, ref: HTMLElement | null) => void;\n\n /**\n * Wraps dom with a context. Will receive render context, produced by `onBeforeRender()` (at server-side) or `deserialize()` (at the browser)\n */\n reactContext?: ComponentType<ContextProps<RenderCtx>>;\n};\n"],"mappings":""}
@@ -1,56 +0,0 @@
1
- /// <reference types="node" />
2
- import type { IncomingHttpHeaders } from 'http';
3
- export declare type ParsedQuery = {
4
- [key: string]: undefined | string | string[] | ParsedQuery | ParsedQuery[];
5
- };
6
- export declare type BrowserData = {
7
- connection: {
8
- secure: boolean;
9
- headers: IncomingHttpHeaders;
10
- body: any;
11
- };
12
- /**
13
- * isomorphic location object, resembling the browser's window.location
14
- */
15
- location: {
16
- /** hostname + port
17
- * @example localhost:3000
18
- */
19
- host: string;
20
- /**
21
- * @example localhost
22
- */
23
- hostname: string;
24
- /** full url
25
- * @example http://localhost:3000/components?q=button
26
- */
27
- href: string;
28
- /** full url without query
29
- * @example http://localhost:3000/components
30
- */
31
- origin: string;
32
- /**
33
- * @example /component
34
- */
35
- pathname: string;
36
- /**
37
- * @example 3000
38
- */
39
- port: number;
40
- /**
41
- * @example http
42
- */
43
- protocol: string;
44
- /**
45
- * parsed search params
46
- * @example { one: 1, two: [2,3]}
47
- */
48
- query: ParsedQuery;
49
- /**
50
- * full resource path, including query, without hostname
51
- * @example /components?q=button
52
- */
53
- url: string;
54
- };
55
- cookie?: string;
56
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- //# sourceMappingURL=request-browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["request-browser.ts"],"sourcesContent":["import type { IncomingHttpHeaders } from 'http';\n\nexport type ParsedQuery = { [key: string]: undefined | string | string[] | ParsedQuery | ParsedQuery[] };\n\nexport type BrowserData = {\n connection: {\n secure: boolean;\n headers: IncomingHttpHeaders;\n body: any;\n };\n /**\n * isomorphic location object, resembling the browser's window.location\n */\n location: {\n /** hostname + port\n * @example localhost:3000\n */\n host: string;\n /**\n * @example localhost\n */\n hostname: string;\n /** full url\n * @example http://localhost:3000/components?q=button\n */\n href: string;\n /** full url without query\n * @example http://localhost:3000/components\n */\n origin: string;\n /**\n * @example /component\n */\n pathname: string;\n /**\n * @example 3000\n */\n port: number;\n /**\n * @example http\n */\n protocol: string;\n /**\n * parsed search params\n * @example { one: 1, two: [2,3]}\n */\n query: ParsedQuery;\n /**\n * full resource path, including query, without hostname\n * @example /components?q=button\n */\n url: string;\n };\n cookie?: string;\n};\n"],"mappings":""}
@@ -1,9 +0,0 @@
1
- import type { Request, Response } from 'express';
2
- /**
3
- * Represents the server configuration for the current request
4
- */
5
- export declare type RequestServer = {
6
- port: number;
7
- request: Request;
8
- response: Response;
9
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- //# sourceMappingURL=request-server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["request-server.ts"],"sourcesContent":["import type { Request, Response } from 'express';\n\n/**\n * Represents the server configuration for the current request\n */\nexport type RequestServer = {\n port: number;\n request: Request;\n response: Response;\n};\n"],"mappings":""}
@@ -1,8 +0,0 @@
1
- import type { Assets } from '@teambit/ui-foundation.ui.rendering.html';
2
- import { BrowserData } from './request-browser';
3
- import { RequestServer } from './request-server';
4
- export declare type SsrContent = {
5
- assets?: Assets;
6
- browser?: BrowserData;
7
- server?: RequestServer;
8
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- //# sourceMappingURL=ssr-content.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["ssr-content.ts"],"sourcesContent":["import type { Assets } from '@teambit/ui-foundation.ui.rendering.html';\nimport { BrowserData } from './request-browser';\nimport { RequestServer } from './request-server';\n\nexport type SsrContent = {\n assets?: Assets;\n browser?: BrowserData;\n server?: RequestServer;\n};\n"],"mappings":""}
@@ -1,6 +0,0 @@
1
- import { Request } from 'express';
2
- import { BrowserData } from '../react-ssr';
3
- /**
4
- * extract relevant information from Express request.
5
- */
6
- export declare function extractBrowserData(req: Request, port: number): BrowserData;
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.extractBrowserData = extractBrowserData;
7
-
8
- /**
9
- * extract relevant information from Express request.
10
- */
11
- function extractBrowserData(req, port) {
12
- const browser = {
13
- connection: {
14
- secure: req.secure,
15
- headers: req.headers,
16
- body: req.body
17
- },
18
- // rebuild browser location from request, +port
19
- location: {
20
- host: `${req.hostname}:${port}`,
21
- hostname: req.hostname,
22
- href: `${req.protocol}://${req.hostname}:${port}${req.url}`,
23
- origin: `${req.protocol}://${req.hostname}:${port}`,
24
- pathname: req.path,
25
- port,
26
- protocol: `${req.protocol}:`,
27
- query: req.query,
28
- url: req.url
29
- },
30
- cookie: req.header('Cookie')
31
- };
32
- return browser;
33
- }
34
-
35
- //# sourceMappingURL=extract-browser-data.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["extractBrowserData","req","port","browser","connection","secure","headers","body","location","host","hostname","href","protocol","url","origin","pathname","path","query","cookie","header"],"sources":["extract-browser-data.ts"],"sourcesContent":["import { Request } from 'express';\nimport { BrowserData } from '../react-ssr';\n\n/**\n * extract relevant information from Express request.\n */\n\nexport function extractBrowserData(req: Request, port: number) {\n const browser: BrowserData = {\n connection: {\n secure: req.secure,\n headers: req.headers,\n body: req.body,\n },\n // rebuild browser location from request, +port\n location: {\n host: `${req.hostname}:${port}`,\n hostname: req.hostname,\n href: `${req.protocol}://${req.hostname}:${port}${req.url}`,\n origin: `${req.protocol}://${req.hostname}:${port}`,\n pathname: req.path,\n port,\n protocol: `${req.protocol}:`,\n query: req.query,\n url: req.url,\n },\n cookie: req.header('Cookie'),\n };\n\n return browser;\n}\n"],"mappings":";;;;;;;AAGA;AACA;AACA;AAEO,SAASA,kBAAT,CAA4BC,GAA5B,EAA0CC,IAA1C,EAAwD;EAC7D,MAAMC,OAAoB,GAAG;IAC3BC,UAAU,EAAE;MACVC,MAAM,EAAEJ,GAAG,CAACI,MADF;MAEVC,OAAO,EAAEL,GAAG,CAACK,OAFH;MAGVC,IAAI,EAAEN,GAAG,CAACM;IAHA,CADe;IAM3B;IACAC,QAAQ,EAAE;MACRC,IAAI,EAAG,GAAER,GAAG,CAACS,QAAS,IAAGR,IAAK,EADtB;MAERQ,QAAQ,EAAET,GAAG,CAACS,QAFN;MAGRC,IAAI,EAAG,GAAEV,GAAG,CAACW,QAAS,MAAKX,GAAG,CAACS,QAAS,IAAGR,IAAK,GAAED,GAAG,CAACY,GAAI,EAHlD;MAIRC,MAAM,EAAG,GAAEb,GAAG,CAACW,QAAS,MAAKX,GAAG,CAACS,QAAS,IAAGR,IAAK,EAJ1C;MAKRa,QAAQ,EAAEd,GAAG,CAACe,IALN;MAMRd,IANQ;MAORU,QAAQ,EAAG,GAAEX,GAAG,CAACW,QAAS,GAPlB;MAQRK,KAAK,EAAEhB,GAAG,CAACgB,KARH;MASRJ,GAAG,EAAEZ,GAAG,CAACY;IATD,CAPiB;IAkB3BK,MAAM,EAAEjB,GAAG,CAACkB,MAAJ,CAAW,QAAX;EAlBmB,CAA7B;EAqBA,OAAOhB,OAAP;AACD"}
Binary file
@@ -1,6 +0,0 @@
1
- export { ReactSSR } from './react-ssr';
2
-
3
- export type { ContextProps, RenderPlugins } from './render-lifecycle';
4
- export type { BrowserData, ParsedQuery } from './request-browser';
5
- export type { RequestServer } from './request-server';
6
- export type { SsrContent } from './ssr-content';