|
9 | 9 |
|
10 | 10 | import { View } from '@athenna/view' |
11 | 11 | import type { FastifyReply } from 'fastify' |
12 | | -import { Server } from '#src/facades/Server' |
13 | | -import { Module, Options } from '@athenna/common' |
14 | 12 | import type { SendOptions } from '@fastify/static' |
15 | 13 | import type { Request } from '#src/context/Request' |
16 | 14 | import type { FastifyHelmetOptions } from '@fastify/helmet' |
17 | 15 |
|
18 | | -let reactDom = Module.safeImport('react-dom/server') as any |
19 | | - |
20 | 16 | export class Response { |
21 | 17 | /** |
22 | 18 | * The fastify response object. |
@@ -146,60 +142,6 @@ export class Response { |
146 | 142 | return this.html(content) |
147 | 143 | } |
148 | 144 |
|
149 | | - /** |
150 | | - * Terminate the request sending a React component to be rendered. |
151 | | - * |
152 | | - * @example |
153 | | - * ```ts |
154 | | - * return response.render('index') |
155 | | - * return response.render('index', { |
156 | | - * component: 'src/resources/app/app.tsx', |
157 | | - * viewData: {}, |
158 | | - * beforeComponentRender: (component) => { |
159 | | - * return component.createApp() |
160 | | - * } |
161 | | - * }) |
162 | | - * ``` |
163 | | - */ |
164 | | - public async render( |
165 | | - view: string, |
166 | | - options?: { |
167 | | - component?: string |
168 | | - viewData?: any |
169 | | - beforeComponentRender?: (componentModule: any) => any |
170 | | - } |
171 | | - ) { |
172 | | - if (!reactDom) { |
173 | | - throw new Error( |
174 | | - 'React is not installed, please run "npm i react react-dom".' |
175 | | - ) |
176 | | - } |
177 | | - |
178 | | - reactDom = await reactDom |
179 | | - |
180 | | - options = Options.create(options, { |
181 | | - viewData: {}, |
182 | | - component: Config.get('http.vite.ssrEntrypoint'), |
183 | | - beforeComponentRender: options?.component |
184 | | - ? null |
185 | | - : component => { |
186 | | - return component.createApp(this.request.baseUrl) |
187 | | - } |
188 | | - }) |
189 | | - |
190 | | - const vite = Server.getVitePlugin().getVite() |
191 | | - let component = await vite.ssrLoadModule(options.component) |
192 | | - |
193 | | - if (options.beforeComponentRender) { |
194 | | - component = options.beforeComponentRender(component) |
195 | | - } |
196 | | - |
197 | | - return this.view(view, { |
198 | | - element: reactDom.renderToString(component), |
199 | | - ...options.viewData |
200 | | - }) |
201 | | - } |
202 | | - |
203 | 145 | /** |
204 | 146 | * Terminate the request sending the response body or not. |
205 | 147 | * |
|
0 commit comments