analogjs / analog

The fullstack meta-framework for Angular. Powered by Vite and Nitro
https://analogjs.org
MIT License
2.59k stars 250 forks source link

[Bug] nitro.compressPublicAssets = true breaks SSR on / route #1360

Open renatoaraujoc opened 1 month ago

renatoaraujoc commented 1 month ago

Please provide the environment you discovered this bug in.

There's no need for an environement.

Which area/package is the issue in?

vite-plugin-nitro

Description

When opt-in for compressPublicAssets, the following analog() config fails to render / route as SSR and just spits out the non-rendered version of it, example:

analog({
    ssr: true,
    prerender: {
        routes: ['/']
    },
    nitro: {
        routeRules: {
            '/': {
                prerender: false
            }
        },
        compressPublicAssets: true, // or { brotli: true, gzip: true }
    }
})

The above will create 1/2 files (depending on the config):

./dist/app/analog/public/index.html.gz ./dist/app/analog/public/index.html.br

Screenshot 2024-09-22 at 06 49 08

The files above will be reconized by nitro server as static assets and will not go thru the SSR rendering, as seen here:

Screenshot 2024-09-22 at 06 51 44

Screenshot 2024-09-22 at 06 52 26

Turning off compressPublicAssets solves the issue and / is renderable again, but we lose the compressed stuff.

Solution: strip out index.html from being .gz'd and br'd in the public folder so nitro server doesn't include it on the assets array.

Please provide the exception or error you saw

No response

Other information

No response

I would be willing to submit a PR to fix this issue