@umijs/renderer-react 4.0.0-canary.20240402.1 → 4.0.0-canary.20240419.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/dist/browser.js CHANGED
@@ -252,11 +252,12 @@ export function renderClient(opts) {
252
252
  var loaderData = window.__UMI_LOADER_DATA__ || {};
253
253
  // @ts-ignore
254
254
  var metadata = window.__UMI_METADATA_LOADER_DATA__ || {};
255
- ReactDOM.hydrateRoot(opts.renderFromRoot ? rootElement : document, /*#__PURE__*/React.createElement(Html, {
255
+ var hydtateHtmloptions = {
256
256
  metadata: metadata,
257
257
  loaderData: loaderData,
258
258
  mountElementId: opts.mountElementId
259
- }, /*#__PURE__*/React.createElement(Browser, null)));
259
+ };
260
+ ReactDOM.hydrateRoot(opts.renderFromRoot ? rootElement : document, /*#__PURE__*/React.createElement(Html, hydtateHtmloptions, /*#__PURE__*/React.createElement(Browser, null)));
260
261
  return;
261
262
  }
262
263
  if (ReactDOM.createRoot) {
package/dist/html.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
2
  import { IHtmlProps } from './types';
3
- export declare function Html({ children, loaderData, manifest, tplOpts, renderFromRoot, mountElementId, }: React.PropsWithChildren<IHtmlProps>): JSX.Element;
3
+ export declare function Html({ children, loaderData, manifest, htmlPageOpts, renderFromRoot, mountElementId, }: React.PropsWithChildren<IHtmlProps>): JSX.Element;
package/dist/html.js CHANGED
@@ -33,31 +33,31 @@ function generatorStyle(style) {
33
33
  };
34
34
  }
35
35
  var HydrateMetadata = function HydrateMetadata(props) {
36
- var _tplOpts$favicons, _tplOpts$keywords, _tplOpts$metas, _tplOpts$links, _tplOpts$styles, _tplOpts$headScripts;
37
- var tplOpts = props.tplOpts;
38
- return /*#__PURE__*/React.createElement(React.Fragment, null, (tplOpts === null || tplOpts === void 0 ? void 0 : tplOpts.title) && /*#__PURE__*/React.createElement("title", null, tplOpts.title), tplOpts === null || tplOpts === void 0 || (_tplOpts$favicons = tplOpts.favicons) === null || _tplOpts$favicons === void 0 ? void 0 : _tplOpts$favicons.map(function (favicon, key) {
36
+ var _htmlPageOpts$favicon, _htmlPageOpts$keyword, _htmlPageOpts$metas, _htmlPageOpts$links, _htmlPageOpts$styles, _htmlPageOpts$headScr;
37
+ var htmlPageOpts = props.htmlPageOpts;
38
+ return /*#__PURE__*/React.createElement(React.Fragment, null, (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.title) && /*#__PURE__*/React.createElement("title", null, htmlPageOpts.title), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$favicon = htmlPageOpts.favicons) === null || _htmlPageOpts$favicon === void 0 ? void 0 : _htmlPageOpts$favicon.map(function (favicon, key) {
39
39
  return /*#__PURE__*/React.createElement("link", {
40
40
  key: key,
41
41
  rel: "shortcut icon",
42
42
  href: favicon
43
43
  });
44
- }), (tplOpts === null || tplOpts === void 0 ? void 0 : tplOpts.description) && /*#__PURE__*/React.createElement("meta", {
44
+ }), (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.description) && /*#__PURE__*/React.createElement("meta", {
45
45
  name: "description",
46
- content: tplOpts.description
47
- }), (tplOpts === null || tplOpts === void 0 || (_tplOpts$keywords = tplOpts.keywords) === null || _tplOpts$keywords === void 0 ? void 0 : _tplOpts$keywords.length) && /*#__PURE__*/React.createElement("meta", {
46
+ content: htmlPageOpts.description
47
+ }), (htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$keyword = htmlPageOpts.keywords) === null || _htmlPageOpts$keyword === void 0 ? void 0 : _htmlPageOpts$keyword.length) && /*#__PURE__*/React.createElement("meta", {
48
48
  name: "keywords",
49
- content: tplOpts.keywords.join(',')
50
- }), tplOpts === null || tplOpts === void 0 || (_tplOpts$metas = tplOpts.metas) === null || _tplOpts$metas === void 0 ? void 0 : _tplOpts$metas.map(function (em) {
49
+ content: htmlPageOpts.keywords.join(',')
50
+ }), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$metas = htmlPageOpts.metas) === null || _htmlPageOpts$metas === void 0 ? void 0 : _htmlPageOpts$metas.map(function (em) {
51
51
  return /*#__PURE__*/React.createElement("meta", {
52
52
  key: em.name,
53
53
  name: em.name,
54
54
  content: em.content
55
55
  });
56
- }), tplOpts === null || tplOpts === void 0 || (_tplOpts$links = tplOpts.links) === null || _tplOpts$links === void 0 ? void 0 : _tplOpts$links.map(function (link, key) {
56
+ }), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$links = htmlPageOpts.links) === null || _htmlPageOpts$links === void 0 ? void 0 : _htmlPageOpts$links.map(function (link, key) {
57
57
  return /*#__PURE__*/React.createElement("link", _extends({
58
58
  key: key
59
59
  }, link));
60
- }), tplOpts === null || tplOpts === void 0 || (_tplOpts$styles = tplOpts.styles) === null || _tplOpts$styles === void 0 ? void 0 : _tplOpts$styles.map(function (style, key) {
60
+ }), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$styles = htmlPageOpts.styles) === null || _htmlPageOpts$styles === void 0 ? void 0 : _htmlPageOpts$styles.map(function (style, key) {
61
61
  var _generatorStyle = generatorStyle(style),
62
62
  type = _generatorStyle.type,
63
63
  href = _generatorStyle.href,
@@ -73,7 +73,7 @@ var HydrateMetadata = function HydrateMetadata(props) {
73
73
  key: key
74
74
  }, content);
75
75
  }
76
- }), tplOpts === null || tplOpts === void 0 || (_tplOpts$headScripts = tplOpts.headScripts) === null || _tplOpts$headScripts === void 0 ? void 0 : _tplOpts$headScripts.map(function (script, key) {
76
+ }), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$headScr = htmlPageOpts.headScripts) === null || _htmlPageOpts$headScr === void 0 ? void 0 : _htmlPageOpts$headScr.map(function (script, key) {
77
77
  var _normalizeScripts = normalizeScripts(script),
78
78
  content = _normalizeScripts.content,
79
79
  rest = _objectWithoutProperties(_normalizeScripts, _excluded);
@@ -83,57 +83,60 @@ var HydrateMetadata = function HydrateMetadata(props) {
83
83
  }));
84
84
  };
85
85
  export function Html(_ref) {
86
- var _tplOpts$scripts;
86
+ var _htmlPageOpts$scripts;
87
87
  var children = _ref.children,
88
88
  loaderData = _ref.loaderData,
89
89
  manifest = _ref.manifest,
90
- tplOpts = _ref.tplOpts,
90
+ htmlPageOpts = _ref.htmlPageOpts,
91
91
  renderFromRoot = _ref.renderFromRoot,
92
92
  mountElementId = _ref.mountElementId;
93
93
  // TODO: 处理 head 标签,比如 favicon.ico 的一致性
94
94
  // TODO: root 支持配置
95
95
  if (renderFromRoot) {
96
96
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(HydrateMetadata, {
97
- tplOpts: tplOpts
97
+ htmlPageOpts: htmlPageOpts
98
98
  }), /*#__PURE__*/React.createElement("div", {
99
99
  id: mountElementId
100
100
  }, children));
101
101
  }
102
- // @ts-ignore
103
102
  var serverBuildManifest = typeof window === 'undefined' ? manifest :
104
103
  // @ts-ignore
105
104
  window.__UMI_BUILD_MANIFEST_DATA__;
106
- return /*#__PURE__*/React.createElement("html", {
107
- suppressHydrationWarning: true,
108
- lang: (tplOpts === null || tplOpts === void 0 ? void 0 : tplOpts.lang) || 'en'
109
- }, /*#__PURE__*/React.createElement("head", null, /*#__PURE__*/React.createElement("meta", {
110
- charSet: "utf-8"
111
- }), /*#__PURE__*/React.createElement("meta", {
112
- name: "viewport",
113
- content: "width=device-width, initial-scale=1"
114
- }), (serverBuildManifest === null || serverBuildManifest === void 0 ? void 0 : serverBuildManifest.assets['umi.css']) && /*#__PURE__*/React.createElement("link", {
115
- suppressHydrationWarning: true,
116
- rel: "stylesheet",
117
- href: manifest === null || manifest === void 0 ? void 0 : manifest.assets['umi.css']
118
- }), /*#__PURE__*/React.createElement(HydrateMetadata, {
119
- tplOpts: tplOpts
120
- })), /*#__PURE__*/React.createElement("body", null, /*#__PURE__*/React.createElement("noscript", {
121
- dangerouslySetInnerHTML: {
122
- __html: "<b>Enable JavaScript to run this app.</b>"
123
- }
124
- }), /*#__PURE__*/React.createElement("div", {
125
- id: mountElementId
126
- }, children), /*#__PURE__*/React.createElement("script", {
127
- suppressHydrationWarning: true,
128
- dangerouslySetInnerHTML: {
129
- __html: "window.__UMI_LOADER_DATA__ = ".concat(JSON.stringify(loaderData || {}), "; window.__UMI_METADATA_LOADER_DATA__ = ").concat(JSON.stringify(tplOpts || {}), "; window.__UMI_BUILD_MANIFEST_DATA__ = ").concat(JSON.stringify(manifest) || {})
130
- }
131
- }), tplOpts === null || tplOpts === void 0 || (_tplOpts$scripts = tplOpts.scripts) === null || _tplOpts$scripts === void 0 ? void 0 : _tplOpts$scripts.map(function (script, key) {
132
- var _normalizeScripts2 = normalizeScripts(script),
133
- content = _normalizeScripts2.content,
134
- rest = _objectWithoutProperties(_normalizeScripts2, _excluded2);
135
- return /*#__PURE__*/React.createElement("script", _extends({
136
- key: key
137
- }, rest), content);
138
- })));
105
+ return (
106
+ /*#__PURE__*/
107
+ // FIXME: Resolve the hydrate warning for suppressHydrationWarning(3)
108
+ React.createElement("html", {
109
+ suppressHydrationWarning: true,
110
+ lang: (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.lang) || 'en'
111
+ }, /*#__PURE__*/React.createElement("head", null, /*#__PURE__*/React.createElement("meta", {
112
+ charSet: "utf-8"
113
+ }), /*#__PURE__*/React.createElement("meta", {
114
+ name: "viewport",
115
+ content: "width=device-width, initial-scale=1"
116
+ }), (serverBuildManifest === null || serverBuildManifest === void 0 ? void 0 : serverBuildManifest.assets['umi.css']) && /*#__PURE__*/React.createElement("link", {
117
+ suppressHydrationWarning: true,
118
+ rel: "stylesheet",
119
+ href: manifest === null || manifest === void 0 ? void 0 : manifest.assets['umi.css']
120
+ }), /*#__PURE__*/React.createElement(HydrateMetadata, {
121
+ htmlPageOpts: htmlPageOpts
122
+ })), /*#__PURE__*/React.createElement("body", null, /*#__PURE__*/React.createElement("noscript", {
123
+ dangerouslySetInnerHTML: {
124
+ __html: "<b>Enable JavaScript to run this app.</b>"
125
+ }
126
+ }), /*#__PURE__*/React.createElement("div", {
127
+ id: mountElementId
128
+ }, children), /*#__PURE__*/React.createElement("script", {
129
+ suppressHydrationWarning: true,
130
+ dangerouslySetInnerHTML: {
131
+ __html: "window.__UMI_LOADER_DATA__ = ".concat(JSON.stringify(loaderData || {}), "; window.__UMI_METADATA_LOADER_DATA__ = ").concat(JSON.stringify(htmlPageOpts || {}), "; window.__UMI_BUILD_MANIFEST_DATA__ = ").concat(JSON.stringify(manifest) || {})
132
+ }
133
+ }), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$scripts = htmlPageOpts.scripts) === null || _htmlPageOpts$scripts === void 0 ? void 0 : _htmlPageOpts$scripts.map(function (script, key) {
134
+ var _normalizeScripts2 = normalizeScripts(script),
135
+ content = _normalizeScripts2.content,
136
+ rest = _objectWithoutProperties(_normalizeScripts2, _excluded2);
137
+ return /*#__PURE__*/React.createElement("script", _extends({
138
+ key: key
139
+ }, rest), content);
140
+ })))
141
+ );
139
142
  }
package/dist/server.js CHANGED
@@ -18,11 +18,18 @@ function _getClientRootComponent() {
18
18
  while (1) switch (_context.prev = _context.next) {
19
19
  case 0:
20
20
  basename = '/';
21
- components = _objectSpread({}, opts.routeComponents);
21
+ components = _objectSpread({}, opts.routeComponents); // todo 参数对齐
22
22
  clientRoutes = createClientRoutes({
23
23
  routesById: opts.routes,
24
24
  routeComponents: components
25
25
  });
26
+ opts.pluginManager.applyPlugins({
27
+ key: 'patchClientRoutes',
28
+ type: 'event',
29
+ args: {
30
+ routes: clientRoutes
31
+ }
32
+ });
26
33
  rootContainer = /*#__PURE__*/React.createElement(StaticRouter, {
27
34
  basename: basename,
28
35
  location: opts.location
@@ -50,7 +57,7 @@ function _getClientRootComponent() {
50
57
  }
51
58
  }, rootContainer);
52
59
  return _context.abrupt("return", /*#__PURE__*/React.createElement(Html, opts, app));
53
- case 7:
60
+ case 8:
54
61
  case "end":
55
62
  return _context.stop();
56
63
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { ITplOpts } from '@umijs/server/dist/types';
2
+ import type { IhtmlPageOpts } from '@umijs/server/dist/types';
3
3
  import type { RouteMatch, RouteObject } from 'react-router-dom';
4
4
  export interface IRouteSSRProps {
5
5
  clientLoader?: () => Promise<any>;
@@ -34,7 +34,12 @@ export interface IRouteComponents {
34
34
  export interface ILoaderData {
35
35
  [routeKey: string]: any;
36
36
  }
37
- export interface IRootComponentOptions {
37
+ interface IHtmlHydrateOptions {
38
+ htmlPageOpts?: IhtmlPageOpts;
39
+ renderFromRoot?: boolean;
40
+ mountElementId?: string;
41
+ }
42
+ export interface IRootComponentOptions extends IHtmlHydrateOptions {
38
43
  routes: IRoutesById;
39
44
  routeComponents: IRouteComponents;
40
45
  pluginManager: any;
@@ -43,19 +48,13 @@ export interface IRootComponentOptions {
43
48
  [routeKey: string]: any;
44
49
  };
45
50
  manifest: any;
46
- tplOpts?: ITplOpts;
47
- renderFromRoot: boolean;
48
- mountElementId: string;
49
51
  }
50
- export interface IHtmlProps {
52
+ export interface IHtmlProps extends IHtmlHydrateOptions {
51
53
  children?: React.ReactNode;
52
54
  loaderData?: {
53
55
  [routeKey: string]: any;
54
56
  };
55
57
  manifest?: any;
56
- tplOpts?: ITplOpts;
57
- mountElementId?: string;
58
- renderFromRoot?: boolean;
59
58
  }
60
59
  export declare type IScript = Partial<{
61
60
  async: boolean;
@@ -66,3 +65,4 @@ export declare type IScript = Partial<{
66
65
  src: string;
67
66
  type: string;
68
67
  }> | string;
68
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/renderer-react",
3
- "version": "4.0.0-canary.20240402.1",
3
+ "version": "4.0.0-canary.20240419.1",
4
4
  "description": "@umijs/renderer-react",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/renderer-react#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",