@athenna/http 5.20.0 → 5.22.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/package.json +1 -1
- package/src/context/Response.js +6 -5
package/package.json
CHANGED
package/src/context/Response.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { View } from '@athenna/view';
|
|
10
10
|
import { Server } from '#src/facades/Server';
|
|
11
11
|
import { Module, Options } from '@athenna/common';
|
|
12
|
-
|
|
12
|
+
let reactDom = Module.safeImport('react-dom/server');
|
|
13
13
|
export class Response {
|
|
14
14
|
constructor(response, request) {
|
|
15
15
|
this.response = response;
|
|
@@ -134,13 +134,14 @@ export class Response {
|
|
|
134
134
|
* ```
|
|
135
135
|
*/
|
|
136
136
|
async render(view, options) {
|
|
137
|
-
if (!
|
|
138
|
-
throw new Error('React is not installed, please run "npm i react".');
|
|
137
|
+
if (!reactDom) {
|
|
138
|
+
throw new Error('React is not installed, please run "npm i react react-dom".');
|
|
139
139
|
}
|
|
140
|
+
reactDom = await reactDom;
|
|
140
141
|
options = Options.create(options, {
|
|
141
142
|
viewData: {},
|
|
142
143
|
component: Config.get('http.vite.ssrEntrypoint'),
|
|
143
|
-
beforeComponentRender: options
|
|
144
|
+
beforeComponentRender: options?.component
|
|
144
145
|
? null
|
|
145
146
|
: component => {
|
|
146
147
|
return component.createApp(this.request.baseUrl);
|
|
@@ -152,7 +153,7 @@ export class Response {
|
|
|
152
153
|
component = options.beforeComponentRender(component);
|
|
153
154
|
}
|
|
154
155
|
return this.view(view, {
|
|
155
|
-
element:
|
|
156
|
+
element: reactDom.renderToString(component),
|
|
156
157
|
...options.viewData
|
|
157
158
|
});
|
|
158
159
|
}
|