You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ionic component styles not loading with Angular SSR #5096
Description:
I'm using Angular 18 standalone application with Ionic 8 and enabled server side rendering. When I try to run SSR, the styles of ionic components are not loading. It just loads the plain html.
const commonEngine = new CommonEngine({
enablePerformanceProfiler: true
});
// Cerca dinamicamente il file CSS generato con hash
const cssFileName = readdirSync(distFolder).find(
(file) => file.startsWith('styles') && file.endsWith('.css')
);
server.set('view engine', 'html');
server.set('views', distFolder);
// Serve i file statici
server.get(
'*.*',
express.static(distFolder, {
maxAge: '1y'
})
);
// Gestisce tutte le altre richieste utilizzando l'engine Angular
server.get('*', (req, res, next) => {
const { protocol, originalUrl, baseUrl, headers } = req;
commonEngine
.render({
bootstrap,
documentFilePath: indexHtml,
url: `${protocol}://${headers.host}${originalUrl}`,
publicPath: distFolder,
inlineCriticalCss: false,
providers: [
{ provide: APP_BASE_HREF, useValue: req.baseUrl },
{ provide: 'REQUEST', useValue: req },
{ provide: 'RESPONSE', useValue: res }
]
})
.then((html) => {
// Inietta dinamicamente il CSS nel contenuto HTML generato
if (cssFileName) {
html = html.replace(
'</head>',
`<link rel="stylesheet" href="${cssFileName}"></head>`
);
}
res.send(html);
})
.catch((err) => next(err));
});
return server;
}
function run(): void {
const port = process.env['PORT'] || 4000;
// Avvia il server Node
const server = app();
server.listen(port, () => {
console.log(`Node Express server listening on http://localhost:${port}`);
});
Activity
sureshkumarsendrayan commentedon Oct 10, 2024
Providing server.ts code below.
`import 'zone.js/node';
import { APP_BASE_HREF } from '@angular/common';
import { CommonEngine } from '@angular/ssr';
import * as express from 'express';
import { existsSync, readdirSync } from 'node:fs';
import { join } from 'node:path';
import bootstrap from './src/main.server';
export function app(): express.Express {
const server = express();
const distFolder = join(process.cwd(), 'dist/app/browser');
const indexHtml = existsSync(join(distFolder, 'index.original.html'))
? join(distFolder, 'index.original.html')
: join(distFolder, 'index.html');
}
function run(): void {
const port = process.env['PORT'] || 4000;
}
declare const non_webpack_require: NodeRequire;
const mainModule = non_webpack_require.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
run();
}
export default bootstrap;
`
sureshkumarsendrayan commentedon Oct 14, 2024
As angular team mentioned here, this issue is not from angular and I expect some reply from Ionic team.
alfred-arcifa-soprasteria commentedon Oct 17, 2024
Yes, I hope to a soon reply form Ionic. It's an hard issue to solve.