Skip to content

Manual <link rel=modulepreload> causes duplication #16269

Closed

Description

@tomayac

Describe the bug

It seems like trying to help vite make sense of a module structure is causing duplication. This is relevant for module workers (see the related #13355), but also in general even for the main script. See the reproduction case and compare the output for rel=preload vs. rel=modulepreload.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ohybcx

Steps to reproduce

Run npm run build.

System Info

System:
    OS: macOS 14.4
    CPU: (8) arm64 Apple M1
    Memory: 73.41 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.7.1 - /opt/homebrew/bin/node
    npm: 10.5.0 - /opt/homebrew/bin/npm
    bun: 0.6.6 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 113.1.51.110
    Chrome: 123.0.6312.59
    Chrome Canary: 125.0.6378.0
    Firefox Nightly: 111.0a1
    Safari: 17.4
    Safari Technology Preview: 17.4

Used Package Manager

npm

Logs

No response

Validations

Activity

  1. bolt-new-by-stackblitz commented on Mar 25, 2024

    @bolt-new-by-stackblitz
  2. added a commit that references this issue on Mar 25, 2024
  3. hi-ogawa commented on Mar 26, 2024

    @hi-ogawa
    Contributor

    I think it's not just duplication, but <link rel="modulepreload" href="/main.js" /> is simply considered as an static asset and the script is not processed. It would be clearer when using typescript like href="/main.ts" https://stackblitz.com/edit/vitejs-vite-u9ok5x?file=dist%2Fassets%2Fmain-zn5ORrD-.ts

    I think this is essentially a same issue as #13355 and it's not supported as a current index.html feature. For now, injecting to <head> manually via plugin as suggested in #13355 (comment) looks like a legitimate solution to me.

  4. tomayac commented on Mar 26, 2024

    @tomayac
    ContributorAuthor

    Thanks, closing in favor of #13355 then. It's still somewhat surprising to me that vite sees independent resources, even if the files have the exact same URL and are being referenced in the same index.html entry point, but I'm absolutely not an expert there, just a naive (and very thankful and content) user.

  5. locked and limited conversation to collaborators on Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions