sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.75k stars 1.95k forks source link

Static adapter compression issue: .br and .gz files incorrectly reference uncompressed files #13031

Closed ouksal closed 2 days ago

ouksal commented 2 days ago

Describe the bug

When using @sveltejs/adapter-static with precompress: true, the .br and .gz files generated during the build process still reference the uncompressed versions of imported files. This breaks expected functionality because compressed files are served instead of their uncompressed counterparts, causing errors.

For instance, if foo.js imports bar.js, the generated foo.js.br and foo.js.gz still reference foo.js instead of foo.js.br or foo.js.gz. This makes the compressed files unusable without manual intervention.

Reproduction

  1. Ensure your svelte.config.js includes:
import adapter from '@sveltejs/adapter-static';

export default {
  kit: {
    adapter: adapter({ precompress: true }),
  },
};
  1. Create a basic Svelte app where foo.js imports bar.js.

src/lib/foo.js

import './bar.js';
console.log('This is foo.js');

src/lib/bar.js console.log('This is bar.js');

  1. Build the app using npm run build

  2. Inspect the generated output by either: Uncompressing one of the .gz or .br files to examine the import statements directly. or: Opening DevTools, navigating to the Network tab, enabling the "Content-Encoding" column, and verifying that files are incorrectly served with the wrong encoding references.

Logs

gzip -d start.TFu5MEUB.js.gz import{c as a}from"../chunks/entry.BAIdZgoF.js";export{a as start};

System Info

System:
    OS: macOS 15.0.1
    CPU: (8) arm64 Apple M1
    Memory: 63.95 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 23.0.0 - /Volumes/SSD-T7/home-SSD/.nvm/versions/node/v23.0.0/bin/node
    npm: 10.9.0 - /Volumes/SSD-T7/home-SSD/.nvm/versions/node/v23.0.0/bin/npm
    bun: 1.0.21 - ~/.bun/bin/bun
  Browsers:
    Chrome: 131.0.6778.70
    Safari: 18.0.1

Severity

blocking all usage of SvelteKit

Additional Information

Expected Behavior: The .br and .gz files should reference the corresponding compressed versions of imported files (bar.js.br or bar.js.gz), ensuring correct behavior when serving compressed files directly.

Conduitry commented 2 days ago

The intention is that the browser would request the .js files for everything, and the server would automatically select the appropriate one, based on the encodings the browser says it can accept. The file would then reference other files with the .js extension. The browser would never be requesting a filename with the .gz or .br extensions.