diff --git a/package-lock.json b/package-lock.json index 8c4da45..7e5927e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/http", - "version": "5.20.0", + "version": "5.21.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/http", - "version": "5.20.0", + "version": "5.21.0", "license": "MIT", "devDependencies": { "@athenna/artisan": "^5.3.0", diff --git a/package.json b/package.json index 5c00c69..8ffc5d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/http", - "version": "5.20.0", + "version": "5.21.0", "description": "The Athenna Http server. Built on top of fastify.", "license": "MIT", "author": "João Lenon ", diff --git a/src/context/Response.ts b/src/context/Response.ts index 46059cf..b9831e9 100644 --- a/src/context/Response.ts +++ b/src/context/Response.ts @@ -15,7 +15,7 @@ import type { SendOptions } from '@fastify/static' import type { Request } from '#src/context/Request' import type { FastifyHelmetOptions } from '@fastify/helmet' -const react = Module.safeImport('react') as any +let reactDom = Module.safeImport('react-dom/server') as any export class Response { /** @@ -169,10 +169,14 @@ export class Response { beforeComponentRender?: (componentModule: any) => any } ) { - if (!react) { - throw new Error('React is not installed, please run "npm i react".') + if (!reactDom) { + throw new Error( + 'React is not installed, please run "npm i react react-dom".' + ) } + reactDom = await reactDom + options = Options.create(options, { viewData: {}, component: Config.get('http.vite.ssrEntrypoint'), @@ -191,7 +195,7 @@ export class Response { } return this.view(view, { - element: react.renderToString(component), + element: reactDom.renderToString(component), ...options.viewData }) }