Replace jsdom with happy-dom for SSR rendering. Update dependencies in package.json and package-lock.json. Adjust documentation in cloud.md to reflect the change in DOM emulation library.
All checks were successful
platform/bro-js/bro.landing/pipeline/head This commit looks good
All checks were successful
platform/bro-js/bro.landing/pipeline/head This commit looks good
This commit is contained in:
@@ -17,30 +17,33 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const React = require('react');
|
||||
const { renderToString } = require('react-dom/server');
|
||||
const { JSDOM } = require('jsdom');
|
||||
const { Window } = require('happy-dom');
|
||||
const { createCanvas } = require('canvas');
|
||||
|
||||
// Читаем index.ejs как основу для SSR
|
||||
const ejsTemplatePath = path.resolve(__dirname, '../src/index.ejs');
|
||||
const ejsTemplate = fs.readFileSync(ejsTemplatePath, 'utf-8');
|
||||
|
||||
// Настройка полноценного DOM окружения через jsdom на основе index.ejs
|
||||
const dom = new JSDOM(ejsTemplate, {
|
||||
// Настройка полноценного DOM окружения через happy-dom на основе index.ejs
|
||||
const window = new Window({
|
||||
url: 'http://localhost',
|
||||
pretendToBeVisual: true,
|
||||
resources: 'usable'
|
||||
width: 1024,
|
||||
height: 768
|
||||
});
|
||||
|
||||
// Расширяем jsdom canvas поддержкой
|
||||
dom.window.HTMLCanvasElement.prototype.getContext = function() {
|
||||
const document = window.document;
|
||||
document.write(ejsTemplate);
|
||||
|
||||
// Расширяем happy-dom canvas поддержкой
|
||||
window.HTMLCanvasElement.prototype.getContext = function() {
|
||||
return createCanvas(200, 200).getContext('2d');
|
||||
};
|
||||
|
||||
global.window = dom.window;
|
||||
global.document = dom.window.document;
|
||||
global.navigator = dom.window.navigator;
|
||||
global.HTMLElement = dom.window.HTMLElement;
|
||||
global.SVGElement = dom.window.SVGElement;
|
||||
global.window = window;
|
||||
global.document = document;
|
||||
global.navigator = window.navigator;
|
||||
global.HTMLElement = window.HTMLElement;
|
||||
global.SVGElement = window.SVGElement;
|
||||
|
||||
console.log('🚀 Запуск SSR с рендерингом React компонентов...');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user