vatts 2.2.6 → 2.3.0-canary.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/LICENSE +12 -12
- package/README.md +65 -65
- package/dist/builder.js +79 -42
- package/dist/frameworks/FrontCore.d.ts +34 -0
- package/dist/frameworks/FrontCore.js +128 -0
- package/dist/{vue → frameworks/builds}/vue.build.js +1 -1
- package/dist/frameworks/react/client.d.ts +8 -0
- package/dist/{react → frameworks/react}/client.js +14 -14
- package/dist/{react → frameworks/react/components}/Link.js +2 -2
- package/dist/frameworks/react/entry.client.d.ts +14 -0
- package/dist/frameworks/react/entry.client.js +211 -0
- package/dist/frameworks/react/react-elements.d.ts +10 -0
- package/dist/{react → frameworks/renderers}/renderer-react.d.ts +2 -2
- package/dist/{react → frameworks/renderers}/renderer-react.js +53 -86
- package/dist/{vue → frameworks/renderers}/renderer.vue.d.ts +2 -2
- package/dist/frameworks/renderers/renderer.vue.js +193 -0
- package/dist/frameworks/themes/BuildingPage.d.ts +1 -0
- package/dist/frameworks/themes/BuildingPage.js +312 -0
- package/dist/frameworks/themes/DefaultNotFound.d.ts +1 -0
- package/dist/frameworks/themes/DefaultNotFound.js +330 -0
- package/dist/frameworks/themes/ErrorModal.d.ts +1 -0
- package/dist/frameworks/themes/ErrorModal.js +345 -0
- package/dist/frameworks/themes/ServerError.d.ts +1 -0
- package/dist/frameworks/themes/ServerError.js +401 -0
- package/dist/frameworks/themes/VattsDevBadge.d.ts +1 -0
- package/dist/frameworks/themes/VattsDevBadge.js +232 -0
- package/dist/frameworks/vue/App.vue +149 -0
- package/dist/frameworks/vue/client.d.ts +9 -0
- package/dist/{vue → frameworks/vue}/client.js +13 -11
- package/dist/{vue → frameworks/vue/components}/Link.vue +38 -38
- package/dist/{vue → frameworks/vue/components}/image/Image.vue +128 -128
- package/dist/frameworks/vue/entry.client.js +75 -0
- package/dist/global/global.d.ts +179 -180
- package/dist/hotReload.js +77 -77
- package/dist/index.js +12 -1
- package/dist/loaders.js +15 -15
- package/dist/renderer.js +2 -2
- package/dist/renderers/common.js +3 -3
- package/dist/utils/core-go.js +2 -2
- package/dist/utils/utils.js +5 -5
- package/package.json +10 -26
- package/dist/react/BuildingPage.d.ts +0 -2
- package/dist/react/BuildingPage.js +0 -270
- package/dist/react/DefaultNotFound.d.ts +0 -2
- package/dist/react/DefaultNotFound.js +0 -248
- package/dist/react/DevIndicator.d.ts +0 -5
- package/dist/react/DevIndicator.js +0 -203
- package/dist/react/ErrorModal.d.ts +0 -20
- package/dist/react/ErrorModal.js +0 -266
- package/dist/react/client.d.ts +0 -8
- package/dist/react/entry.client.d.ts +0 -6
- package/dist/react/entry.client.js +0 -325
- package/dist/react/server-error.d.ts +0 -8
- package/dist/react/server-error.js +0 -346
- package/dist/vue/App.vue +0 -199
- package/dist/vue/BuildingPage.vue +0 -281
- package/dist/vue/DefaultNotFound.vue +0 -329
- package/dist/vue/DevIndicator.vue +0 -226
- package/dist/vue/ErrorModal.vue +0 -317
- package/dist/vue/client.d.ts +0 -9
- package/dist/vue/entry.client.js +0 -110
- package/dist/vue/renderer.vue.js +0 -387
- package/dist/vue/server-error.vue +0 -351
- /package/dist/{react → frameworks/builds}/react.build.d.ts +0 -0
- /package/dist/{react → frameworks/builds}/react.build.js +0 -0
- /package/dist/{vue → frameworks/builds}/vue.build.d.ts +0 -0
- /package/dist/{react → frameworks/react/components}/Link.d.ts +0 -0
- /package/dist/{react → frameworks/react/components}/image/Image.d.ts +0 -0
- /package/dist/{react → frameworks/react/components}/image/Image.js +0 -0
- /package/dist/{vue → frameworks/vue}/entry.client.d.ts +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
/*
|
|
37
|
+
* This file is part of the Vatts.js Project.
|
|
38
|
+
* ...
|
|
39
|
+
*/
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const client_1 = require("react-dom/client");
|
|
42
|
+
const clientRouter_ts_1 = require("../../client/clientRouter.js");
|
|
43
|
+
const FrontCore_1 = require("../FrontCore");
|
|
44
|
+
require("../themes/VattsDevBadge");
|
|
45
|
+
require("../themes/ErrorModal");
|
|
46
|
+
function App({ componentMap, routes, initialComponentPath, initialParams, layoutComponent }) {
|
|
47
|
+
const [hmrTimestamp, setHmrTimestamp] = (0, react_1.useState)(Date.now());
|
|
48
|
+
const pendingHmrReadyRef = (0, react_1.useRef)(null);
|
|
49
|
+
const [buildError, setBuildError] = (0, react_1.useState)(() => {
|
|
50
|
+
const initialError = window.__VATTS_BUILD_ERROR__ || null;
|
|
51
|
+
if (initialError)
|
|
52
|
+
console.warn('[Vatts React] ⚠️ Erro de build inicial detectado:', initialError);
|
|
53
|
+
return initialError;
|
|
54
|
+
});
|
|
55
|
+
const [isErrorOpen, setIsErrorOpen] = (0, react_1.useState)(() => !!window.__VATTS_BUILD_ERROR__);
|
|
56
|
+
const devBadgeRef = (0, react_1.useRef)(null);
|
|
57
|
+
const errorModalRef = (0, react_1.useRef)(null);
|
|
58
|
+
// Setup de eventos compartilhados
|
|
59
|
+
(0, react_1.useEffect)(() => {
|
|
60
|
+
const cleanupErrorEvents = (0, FrontCore_1.setupBuildErrorEvents)((err) => { setBuildError(err); setIsErrorOpen(true); }, () => { setBuildError(null); setIsErrorOpen(false); });
|
|
61
|
+
const cleanupHmrEvents = (0, FrontCore_1.setupHMREvents)((file, timestamp) => {
|
|
62
|
+
setHmrTimestamp(timestamp);
|
|
63
|
+
pendingHmrReadyRef.current = { file, timestamp };
|
|
64
|
+
});
|
|
65
|
+
return () => {
|
|
66
|
+
cleanupErrorEvents();
|
|
67
|
+
cleanupHmrEvents();
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
(0, react_1.useEffect)(() => {
|
|
71
|
+
(0, FrontCore_1.dispatchHmrReady)(pendingHmrReadyRef.current);
|
|
72
|
+
pendingHmrReadyRef.current = null;
|
|
73
|
+
}, [hmrTimestamp]);
|
|
74
|
+
const handleCopyLog = (0, react_1.useCallback)(() => (0, FrontCore_1.copyBuildError)(buildError), [buildError]);
|
|
75
|
+
// Sincroniza refs dos Web Components
|
|
76
|
+
(0, react_1.useEffect)(() => {
|
|
77
|
+
const badge = devBadgeRef.current;
|
|
78
|
+
const modal = errorModalRef.current;
|
|
79
|
+
if (badge)
|
|
80
|
+
badge.setAttribute('has-build-error', buildError ? 'true' : 'false');
|
|
81
|
+
if (modal) {
|
|
82
|
+
modal.error = buildError;
|
|
83
|
+
modal.isOpen = isErrorOpen;
|
|
84
|
+
}
|
|
85
|
+
}, [buildError, isErrorOpen]);
|
|
86
|
+
(0, react_1.useEffect)(() => {
|
|
87
|
+
const badge = devBadgeRef.current;
|
|
88
|
+
const modal = errorModalRef.current;
|
|
89
|
+
const handleBadgeClick = () => setIsErrorOpen(true);
|
|
90
|
+
const handleModalClose = () => setIsErrorOpen(false);
|
|
91
|
+
if (badge)
|
|
92
|
+
badge.addEventListener('click-build-error', handleBadgeClick);
|
|
93
|
+
if (modal) {
|
|
94
|
+
modal.addEventListener('close-modal', handleModalClose);
|
|
95
|
+
modal.addEventListener('copy-log', handleCopyLog);
|
|
96
|
+
}
|
|
97
|
+
return () => {
|
|
98
|
+
if (badge)
|
|
99
|
+
badge.removeEventListener('click-build-error', handleBadgeClick);
|
|
100
|
+
if (modal) {
|
|
101
|
+
modal.removeEventListener('close-modal', handleModalClose);
|
|
102
|
+
modal.removeEventListener('copy-log', handleCopyLog);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}, [handleCopyLog]);
|
|
106
|
+
// Roteamento
|
|
107
|
+
const getMatch = (0, react_1.useCallback)((path) => (0, FrontCore_1.findRouteForPath)(path, routes), [routes]);
|
|
108
|
+
const [CurrentPageComponent, setCurrentPageComponent] = (0, react_1.useState)(() => {
|
|
109
|
+
const currentPath = window.location.pathname.replace("index.html", '');
|
|
110
|
+
const match = getMatch(currentPath);
|
|
111
|
+
return match ? componentMap[match.componentPath] : null;
|
|
112
|
+
});
|
|
113
|
+
const [params, setParams] = (0, react_1.useState)(() => {
|
|
114
|
+
const currentPath = window.location.pathname.replace("index.html", '');
|
|
115
|
+
const match = getMatch(currentPath);
|
|
116
|
+
return match ? match.params : {};
|
|
117
|
+
});
|
|
118
|
+
const updateRoute = (0, react_1.useCallback)(() => {
|
|
119
|
+
const currentPath = clientRouter_ts_1.router.pathname.replace("index.html", '');
|
|
120
|
+
const match = getMatch(currentPath);
|
|
121
|
+
if (match) {
|
|
122
|
+
setCurrentPageComponent(() => componentMap[match.componentPath]);
|
|
123
|
+
setParams(match.params);
|
|
124
|
+
(0, FrontCore_1.updateDocumentTitle)(match.metadata?.title);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.warn(`[Vatts React] ⚠️ Rota não encontrada (404): ${currentPath}`);
|
|
128
|
+
setCurrentPageComponent(null);
|
|
129
|
+
setParams({});
|
|
130
|
+
}
|
|
131
|
+
}, [clientRouter_ts_1.router.pathname, getMatch, componentMap]);
|
|
132
|
+
(0, react_1.useEffect)(() => {
|
|
133
|
+
const handlePopState = () => updateRoute();
|
|
134
|
+
window.addEventListener('popstate', handlePopState);
|
|
135
|
+
const unsubscribe = clientRouter_ts_1.router.subscribe(updateRoute);
|
|
136
|
+
return () => {
|
|
137
|
+
window.removeEventListener('popstate', handlePopState);
|
|
138
|
+
unsubscribe();
|
|
139
|
+
};
|
|
140
|
+
}, [updateRoute]);
|
|
141
|
+
// Renderização
|
|
142
|
+
let resolvedContent;
|
|
143
|
+
if (!CurrentPageComponent || initialComponentPath === '__404__') {
|
|
144
|
+
const NotFoundComponent = window.__VATTS_NOT_FOUND__;
|
|
145
|
+
let NotFoundContent;
|
|
146
|
+
if (NotFoundComponent) {
|
|
147
|
+
NotFoundContent = react_1.default.createElement(NotFoundComponent, null);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
const { getDefaultNotFound } = window.__VATTS_DEFAULT_NOT_FOUND__;
|
|
151
|
+
NotFoundContent = react_1.default.createElement("div", { dangerouslySetInnerHTML: { __html: getDefaultNotFound() } });
|
|
152
|
+
}
|
|
153
|
+
resolvedContent = typeof layoutComponent === "function"
|
|
154
|
+
? react_1.default.createElement(layoutComponent, { children: NotFoundContent })
|
|
155
|
+
: NotFoundContent;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
const PageContent = react_1.default.createElement(CurrentPageComponent, { key: `page-${hmrTimestamp}`, params: params });
|
|
159
|
+
resolvedContent = typeof layoutComponent === "function"
|
|
160
|
+
? react_1.default.createElement(layoutComponent, { children: PageContent })
|
|
161
|
+
: react_1.default.createElement("div", null, PageContent);
|
|
162
|
+
}
|
|
163
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
164
|
+
resolvedContent,
|
|
165
|
+
process.env.NODE_ENV !== 'production' ? (react_1.default.createElement("vatts-dev-badge", { ref: devBadgeRef })) : null,
|
|
166
|
+
react_1.default.createElement("vatts-error-modal", { ref: errorModalRef })));
|
|
167
|
+
}
|
|
168
|
+
// --- Inicialização do Cliente ---
|
|
169
|
+
function initializeClient() {
|
|
170
|
+
try {
|
|
171
|
+
// Resolve a rota e params inicial calculando diretamente no lado do cliente
|
|
172
|
+
// a partir da injeção do esbuild!
|
|
173
|
+
const routes = window.__VATTS_ROUTES__ || [];
|
|
174
|
+
const currentPath = window.location.pathname.replace("index.html", '');
|
|
175
|
+
const match = (0, FrontCore_1.findRouteForPath)(currentPath, routes);
|
|
176
|
+
const initialComponentPath = match ? match.componentPath : '__404__';
|
|
177
|
+
const initialParams = match ? match.params : {};
|
|
178
|
+
const componentMap = {};
|
|
179
|
+
if (window.__VATTS_COMPONENTS__) {
|
|
180
|
+
Object.assign(componentMap, window.__VATTS_COMPONENTS__);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
console.warn('[Vatts React] ⚠️ No components found in window.__VATTS_COMPONENTS__');
|
|
184
|
+
}
|
|
185
|
+
const container = document.getElementById('root');
|
|
186
|
+
if (!container)
|
|
187
|
+
throw new Error('Container #root not found.');
|
|
188
|
+
if (window.__VATTS_ROOT__) {
|
|
189
|
+
console.log('[Vatts React] ♻️ HMR detectado: Limpando a root do React...');
|
|
190
|
+
try {
|
|
191
|
+
window.__VATTS_ROOT__.unmount();
|
|
192
|
+
container.innerHTML = '';
|
|
193
|
+
}
|
|
194
|
+
catch (e) {
|
|
195
|
+
console.warn('[Vatts React] ⚠️ Warning during unmount:', e);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const root = (0, client_1.createRoot)(container);
|
|
199
|
+
window.__VATTS_ROOT__ = root;
|
|
200
|
+
root.render(react_1.default.createElement(App, { componentMap: componentMap, routes: routes, initialComponentPath: initialComponentPath, initialParams: initialParams, layoutComponent: window.__VATTS_LAYOUT__ }));
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
(0, FrontCore_1.renderCriticalError)(error, 'React');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (document.readyState === 'loading') {
|
|
207
|
+
document.addEventListener('DOMContentLoaded', initializeClient);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
setTimeout(initializeClient, 0);
|
|
211
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
declare module 'react' {
|
|
4
|
+
namespace JSX {
|
|
5
|
+
interface IntrinsicElements {
|
|
6
|
+
'vatts-dev-badge': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> | any;
|
|
7
|
+
'vatts-error-modal': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> | any;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RouteConfig } from '
|
|
2
|
-
import type { GenericRequest } from '
|
|
1
|
+
import { RouteConfig } from '../../types.ts';
|
|
2
|
+
import type { GenericRequest } from '../../types/framework.ts';
|
|
3
3
|
interface RenderOptions {
|
|
4
4
|
req: GenericRequest;
|
|
5
5
|
res: any;
|
|
@@ -22,36 +22,35 @@ exports.render = render;
|
|
|
22
22
|
*/
|
|
23
23
|
const react_1 = __importDefault(require("react"));
|
|
24
24
|
const server_1 = require("react-dom/server");
|
|
25
|
-
const
|
|
25
|
+
const router_ts_1 = require("../../router.js");
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
27
|
+
const common_ts_1 = require("../../renderers/common.js");
|
|
28
|
+
// Importa os geradores de HTML Vanilla
|
|
29
|
+
const BuildingPage_1 = require("../themes/BuildingPage");
|
|
30
|
+
const ServerError_1 = require("../themes/ServerError");
|
|
30
31
|
function buildShellHtml(options) {
|
|
31
|
-
const { lang, title, metaTagsHtml, stylesHtml, hotReloadScript,
|
|
32
|
-
return `<!DOCTYPE html>
|
|
33
|
-
<html lang="${lang}">
|
|
34
|
-
<head>
|
|
35
|
-
<meta charset="utf-8" />
|
|
36
|
-
<title>${title}</title>
|
|
37
|
-
${metaTagsHtml || ''}
|
|
38
|
-
${stylesHtml || ''}
|
|
39
|
-
</head>
|
|
40
|
-
<body>
|
|
41
|
-
|
|
42
|
-
<div id="root"></div>
|
|
43
|
-
${scriptsHtml || ''}
|
|
44
|
-
${hotReloadScript ? `<div style="display:none">${hotReloadScript}</div>` : ''}
|
|
45
|
-
</body>
|
|
32
|
+
const { lang, title, metaTagsHtml, stylesHtml, hotReloadScript, scriptsHtml } = options;
|
|
33
|
+
return `<!DOCTYPE html>
|
|
34
|
+
<html lang="${lang}">
|
|
35
|
+
<head>
|
|
36
|
+
<meta charset="utf-8" />
|
|
37
|
+
<title>${title}</title>
|
|
38
|
+
${metaTagsHtml || ''}
|
|
39
|
+
${stylesHtml || ''}
|
|
40
|
+
</head>
|
|
41
|
+
<body>
|
|
42
|
+
|
|
43
|
+
<div id="root"></div>
|
|
44
|
+
${scriptsHtml || ''}
|
|
45
|
+
${hotReloadScript ? `<div style="display:none">${hotReloadScript}</div>` : ''}
|
|
46
|
+
</body>
|
|
46
47
|
</html>`;
|
|
47
48
|
}
|
|
48
49
|
async function sendReactSsrFallback(options) {
|
|
49
|
-
const { req, res, isProduction, error, assets, lang, title, metaTagsHtml, stylesHtml, hotReloadScript,
|
|
50
|
+
const { req, res, isProduction, error, assets, lang, title, metaTagsHtml, stylesHtml, hotReloadScript, } = options;
|
|
50
51
|
const scriptsHtml = assets.scripts
|
|
51
52
|
.map((src) => `<script type="module" src="${src}"></script>`)
|
|
52
53
|
.join('\n');
|
|
53
|
-
// No DEV a gente remove scripts do head pra garantir que só aparece a página de erro.
|
|
54
|
-
const safeMetaTagsHtmlForDev = (0, common_1.stripScriptTags)(metaTagsHtml);
|
|
55
54
|
if (res.headersSent) {
|
|
56
55
|
try {
|
|
57
56
|
res.end();
|
|
@@ -70,50 +69,41 @@ async function sendReactSsrFallback(options) {
|
|
|
70
69
|
metaTagsHtml,
|
|
71
70
|
stylesHtml,
|
|
72
71
|
hotReloadScript: '',
|
|
73
|
-
obfuscatedData,
|
|
74
72
|
scriptsHtml,
|
|
75
73
|
}));
|
|
76
74
|
return;
|
|
77
75
|
}
|
|
78
|
-
const err = (0,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
onError() {
|
|
87
|
-
// ignore (já estamos numa tela de erro)
|
|
88
|
-
},
|
|
89
|
-
onShellError() {
|
|
90
|
-
// fallback extremo
|
|
91
|
-
res.end('<h1>SSR Error</h1>');
|
|
92
|
-
resolve();
|
|
93
|
-
},
|
|
94
|
-
});
|
|
76
|
+
const err = (0, common_ts_1.toError)(error);
|
|
77
|
+
// Gera o HTML do Erro via Vanilla JS
|
|
78
|
+
let errorHtml = (0, ServerError_1.getServerErrorHtml)({
|
|
79
|
+
title: title || 'SSR Error',
|
|
80
|
+
error: err,
|
|
81
|
+
requestUrl: (0, common_ts_1.getRequestUrl)(req),
|
|
82
|
+
hint: "SSR failed to render this route. See the error below."
|
|
95
83
|
});
|
|
84
|
+
// Injeta o script de Hot Reload no HTML cru para continuar escutando mudanças
|
|
85
|
+
if (hotReloadScript) {
|
|
86
|
+
errorHtml = errorHtml.replace('</body>', `<div style="display:none">${hotReloadScript}</div></body>`);
|
|
87
|
+
}
|
|
88
|
+
res.end(errorHtml);
|
|
89
|
+
return Promise.resolve();
|
|
96
90
|
}
|
|
97
|
-
function ServerRoot({ lang, title, metaTagsHtml, stylesHtml, initialDataScript, hotReloadScript,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<
|
|
101
|
-
|
|
102
|
-
${
|
|
103
|
-
${
|
|
104
|
-
${stylesHtml || ''}
|
|
91
|
+
function ServerRoot({ lang, title, metaTagsHtml, stylesHtml, initialDataScript, hotReloadScript, children }) {
|
|
92
|
+
const headContent = `
|
|
93
|
+
<meta charset="utf-8" />
|
|
94
|
+
<title>${title}</title>
|
|
95
|
+
${initialDataScript ? `<script>${initialDataScript}</script>` : ''}
|
|
96
|
+
${metaTagsHtml || ''}
|
|
97
|
+
${stylesHtml || ''}
|
|
105
98
|
`;
|
|
106
99
|
return (react_1.default.createElement("html", { lang: lang },
|
|
107
100
|
react_1.default.createElement("head", { dangerouslySetInnerHTML: { __html: headContent } }),
|
|
108
101
|
react_1.default.createElement("body", null,
|
|
109
|
-
dataScript,
|
|
110
102
|
react_1.default.createElement("div", { id: "root" }, children),
|
|
111
103
|
hotReloadScript && (react_1.default.createElement("div", { style: { display: 'none' }, dangerouslySetInnerHTML: { __html: hotReloadScript } })))));
|
|
112
104
|
}
|
|
113
105
|
async function render({ req, res, route, params, allRoutes }) {
|
|
114
|
-
|
|
115
|
-
// antes de qualquer lógica de componente ser executada.
|
|
116
|
-
(0, common_1.polyfillBrowserEnv)();
|
|
106
|
+
(0, common_ts_1.polyfillBrowserEnv)();
|
|
117
107
|
const { generateMetadata } = route;
|
|
118
108
|
const isProduction = !req.hwebDev;
|
|
119
109
|
const hotReloadManager = req.hotReloadManager;
|
|
@@ -121,24 +111,19 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
121
111
|
let metadata = { title: 'Vatts App' };
|
|
122
112
|
let layoutInfo = null;
|
|
123
113
|
try {
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
assets = (0, common_ts_1.getBuildAssets)();
|
|
115
|
+
// 1. Verificar Build - Envia a página pura em Vanilla JS se não terminou de compilar
|
|
126
116
|
if (!assets || assets.scripts.length === 0) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
130
|
-
pipe(res);
|
|
131
|
-
},
|
|
132
|
-
});
|
|
117
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
118
|
+
res.end((0, BuildingPage_1.getBuildingScreenHtml)());
|
|
133
119
|
return;
|
|
134
120
|
}
|
|
135
121
|
// 2. Preparar Layout
|
|
136
|
-
layoutInfo = (0,
|
|
122
|
+
layoutInfo = (0, router_ts_1.getLayout)();
|
|
137
123
|
let LayoutComponent = null;
|
|
138
124
|
if (layoutInfo) {
|
|
139
125
|
try {
|
|
140
|
-
|
|
141
|
-
const layoutModule = (0, common_1.requireWithoutStyles)(path_1.default.resolve(process.cwd(), layoutInfo.componentPath));
|
|
126
|
+
const layoutModule = (0, common_ts_1.requireWithoutStyles)(path_1.default.resolve(process.cwd(), layoutInfo.componentPath));
|
|
142
127
|
LayoutComponent = layoutModule.default;
|
|
143
128
|
}
|
|
144
129
|
catch (e) {
|
|
@@ -173,12 +158,9 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
173
158
|
initialComponentPath: route.componentPath,
|
|
174
159
|
initialParams: params,
|
|
175
160
|
};
|
|
176
|
-
// Scripts e Estilos
|
|
177
|
-
const obfuscatedData = (0, common_1.obfuscateData)(initialData);
|
|
178
161
|
const hotReloadScript = !isProduction && hotReloadManager ? hotReloadManager.getClientScript() : '';
|
|
179
|
-
const metaTagsHtml = (0,
|
|
162
|
+
const metaTagsHtml = (0, common_ts_1.generateMetaTags)(metadata);
|
|
180
163
|
const htmlLang = metadata.language || 'pt-BR';
|
|
181
|
-
// Gera tags de estilo para o head, garantindo a extensão .css no final para evitar strict MIME checks
|
|
182
164
|
const stylesHtml = assets.styles.map(styleUrl => {
|
|
183
165
|
const [basePath, query] = styleUrl.split('?');
|
|
184
166
|
const finalUrl = !basePath.endsWith('.css') ? `${basePath}.css${query ? `?${query}` : ''}` : styleUrl;
|
|
@@ -186,16 +168,15 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
186
168
|
}).join('\n');
|
|
187
169
|
// 5. Componente da Página Atual
|
|
188
170
|
const PageComponent = route.component;
|
|
189
|
-
// Monta a árvore da aplicação
|
|
190
171
|
let AppTree = react_1.default.createElement(PageComponent, { params: params });
|
|
191
172
|
if (LayoutComponent) {
|
|
192
173
|
AppTree = react_1.default.createElement(LayoutComponent, null, AppTree);
|
|
193
174
|
}
|
|
194
|
-
// 6. Streaming
|
|
175
|
+
// 6. Streaming React
|
|
195
176
|
return new Promise((resolve) => {
|
|
196
177
|
let didError = false;
|
|
197
178
|
let firstError = null;
|
|
198
|
-
const stream = (0, server_1.renderToPipeableStream)(react_1.default.createElement(ServerRoot, { lang: htmlLang, title: metadata.title || 'Vatts.js', metaTagsHtml: metaTagsHtml, stylesHtml: stylesHtml, initialDataScript: `/* Data Injection */`, hotReloadScript: hotReloadScript
|
|
179
|
+
const stream = (0, server_1.renderToPipeableStream)(react_1.default.createElement(ServerRoot, { lang: htmlLang, title: metadata.title || 'Vatts.js', metaTagsHtml: metaTagsHtml, stylesHtml: stylesHtml, initialDataScript: `/* Data Injection */`, hotReloadScript: hotReloadScript }, AppTree), {
|
|
199
180
|
bootstrapModules: assets.scripts,
|
|
200
181
|
onAllReady() {
|
|
201
182
|
if (didError) {
|
|
@@ -211,7 +192,6 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
211
192
|
metaTagsHtml,
|
|
212
193
|
stylesHtml,
|
|
213
194
|
hotReloadScript,
|
|
214
|
-
obfuscatedData,
|
|
215
195
|
}).then(resolve);
|
|
216
196
|
return;
|
|
217
197
|
}
|
|
@@ -235,11 +215,10 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
235
215
|
}
|
|
236
216
|
catch (err) {
|
|
237
217
|
if (!assets) {
|
|
238
|
-
// sem assets não dá pra montar shell completo; evita crash
|
|
239
218
|
if (!res.headersSent) {
|
|
240
219
|
res.statusCode = 500;
|
|
241
220
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
242
|
-
res.end(isProduction ? '' : '
|
|
221
|
+
res.end(isProduction ? '' : (0, ServerError_1.getServerErrorHtml)({ error: err, title: 'Critical SSR Error' }));
|
|
243
222
|
}
|
|
244
223
|
return;
|
|
245
224
|
}
|
|
@@ -253,7 +232,7 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
253
232
|
title: metadata.title || 'Vatts.js',
|
|
254
233
|
metaTagsHtml: (() => {
|
|
255
234
|
try {
|
|
256
|
-
return (0,
|
|
235
|
+
return (0, common_ts_1.generateMetaTags)(metadata);
|
|
257
236
|
}
|
|
258
237
|
catch {
|
|
259
238
|
return '';
|
|
@@ -265,18 +244,6 @@ async function render({ req, res, route, params, allRoutes }) {
|
|
|
265
244
|
return `<link rel="stylesheet" href="${finalUrl}">`;
|
|
266
245
|
}).join('\n'),
|
|
267
246
|
hotReloadScript: !isProduction && hotReloadManager ? hotReloadManager.getClientScript() : '',
|
|
268
|
-
obfuscatedData: (() => {
|
|
269
|
-
try {
|
|
270
|
-
return (0, common_1.obfuscateData)({
|
|
271
|
-
routes: [],
|
|
272
|
-
initialComponentPath: route.componentPath,
|
|
273
|
-
initialParams: params,
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
catch {
|
|
277
|
-
return '';
|
|
278
|
-
}
|
|
279
|
-
})(),
|
|
280
247
|
});
|
|
281
248
|
}
|
|
282
249
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RouteConfig } from '
|
|
2
|
-
import type { GenericRequest } from '
|
|
1
|
+
import { RouteConfig } from '../../types.ts';
|
|
2
|
+
import type { GenericRequest } from '../../types/framework.ts';
|
|
3
3
|
interface RenderOptions {
|
|
4
4
|
req: GenericRequest;
|
|
5
5
|
res: any;
|