Skip to content

Using preloadStrategy: 'preload-mjs' causes wrong CSS link #11428

@srueg

Description

@srueg

Describe the bug

Using the preloadStrategy: 'preload-mjs' option causes the stylesheet <link> to be rendered with as="script".

<link rel="preload" as="script" crossorigin="anonymous" href="/_app/immutable/assets/0.r4pxjvvX.css">

This causes a flicker of unstyled content on first load.

This only seems to be a problem since SvelteKit 2.0

Reproduction

In sevelte.config.js:

output: {
    preloadStrategy: 'preload-mjs'
},

Generated index.html file:

<link rel="preload" as="script" crossorigin="anonymous" href="/_app/immutable/assets/0.r4pxjvvX.css">

Logs

No response

System Info

System:
    OS: macOS 14.2
    CPU: (8) arm64 Apple M1
    Memory: 78.63 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.4.0 - /opt/homebrew/bin/node
    npm: 10.2.4 - /opt/homebrew/bin/npm
    pnpm: 8.12.0 - /opt/homebrew/bin/pnpm
    bun: 1.0.17 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 17.2
  npmPackages:
    @sveltejs/adapter-cloudflare: ^3.0.0 => 3.0.0
    @sveltejs/kit: ^2.0.0 => 2.0.3
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.1
    svelte: ^4.0.5 => 4.2.8
    vite: ^5.0.0 => 5.0.10

Severity

serious, but I can work around it

Additional Information

Workaround: use modulepreload as browser adoption is good enough by now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions