feat: Pre-renderizar la navegación del dashboard para mejorar el rendimiento y evitar promesas no resueltas
This commit is contained in:
@@ -521,6 +521,26 @@ const renderTemplate = async (
|
|||||||
const defaultTitle = `${
|
const defaultTitle = `${
|
||||||
locals.appName ?? pkg.name ?? "Amayo Bot"
|
locals.appName ?? pkg.name ?? "Amayo Bot"
|
||||||
} | Guía Completa`;
|
} | Guía Completa`;
|
||||||
|
// If the caller requested the dashboard nav, render it here and pass the
|
||||||
|
// resulting HTML string to the layout to avoid printing unresolved Promises
|
||||||
|
// in the template (EJS include/await differences across environments).
|
||||||
|
let dashboardNavHtml: string | null = null;
|
||||||
|
try {
|
||||||
|
if (locals.useDashboardNav) {
|
||||||
|
const partialPath = path.join(viewsDir, "partials", "dashboard_nav.ejs");
|
||||||
|
// Render partial with same locals (async)
|
||||||
|
dashboardNavHtml = await ejs.renderFile(
|
||||||
|
partialPath,
|
||||||
|
{ ...locals },
|
||||||
|
{ async: true }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// If rendering the partial fails, log and continue — layout will handle missing nav.
|
||||||
|
console.warn("Failed rendering dashboard_nav partial:", err);
|
||||||
|
dashboardNavHtml = null;
|
||||||
|
}
|
||||||
|
|
||||||
const html = await ejs.renderFile(
|
const html = await ejs.renderFile(
|
||||||
layoutFile,
|
layoutFile,
|
||||||
{
|
{
|
||||||
@@ -543,6 +563,8 @@ const renderTemplate = async (
|
|||||||
typeof locals.useDashboardNav !== "undefined"
|
typeof locals.useDashboardNav !== "undefined"
|
||||||
? locals.useDashboardNav
|
? locals.useDashboardNav
|
||||||
: false,
|
: false,
|
||||||
|
// Pre-rendered partial HTML (if produced above)
|
||||||
|
dashboardNav: dashboardNavHtml,
|
||||||
...locals,
|
...locals,
|
||||||
title: locals.title ?? defaultTitle,
|
title: locals.title ?? defaultTitle,
|
||||||
body: pageBody,
|
body: pageBody,
|
||||||
|
|||||||
@@ -22,7 +22,12 @@
|
|||||||
<body class="min-h-screen pixel-grid-bg pt-14" style="background-image: url('/assets/images/background.svg'); background-size: cover; background-position: center; background-attachment: fixed; background-repeat: no-repeat;">
|
<body class="min-h-screen pixel-grid-bg pt-14" style="background-image: url('/assets/images/background.svg'); background-size: cover; background-position: center; background-attachment: fixed; background-repeat: no-repeat;">
|
||||||
|
|
||||||
<% if (useDashboardNav) { %>
|
<% if (useDashboardNav) { %>
|
||||||
|
<%# If the server pre-rendered the dashboard nav it will be available as dashboardNav (string) %>
|
||||||
|
<% if (typeof dashboardNav !== 'undefined' && dashboardNav) { %>
|
||||||
|
<%- dashboardNav %>
|
||||||
|
<% } else { %>
|
||||||
<%- include('../partials/dashboard_nav') %>
|
<%- include('../partials/dashboard_nav') %>
|
||||||
|
<% } %>
|
||||||
<% } else if (!hideNavbar) { %>
|
<% } else if (!hideNavbar) { %>
|
||||||
<%- include('../partials/navbar', { appName }) %>
|
<%- include('../partials/navbar', { appName }) %>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|||||||
Reference in New Issue
Block a user