Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssrLoadModule returns an identical module for file urls with hash/search #19298

Open
7 tasks done
hi-ogawa opened this issue Jan 27, 2025 · 0 comments · May be fixed by #19300
Open
7 tasks done

ssrLoadModule returns an identical module for file urls with hash/search #19298

hi-ogawa opened this issue Jan 27, 2025 · 0 comments · May be fixed by #19300

Comments

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jan 27, 2025

Describe the bug

import { createServer } from "vite"

const fileUrl = new URL('./hello.js', import.meta.url);
{
  console.log('==== import ====');
  const mod1 = await import(fileUrl.href);
  const mod2 = await import(fileUrl.href + '#bustCache=1');
  const mod3 = await import(fileUrl.href + '?bustCache=1');
  console.log({ mod1, mod2, mod3 });
  console.log('[mod1 === mod2]', mod1 === mod2); // ===> false
  console.log('[mod1 === mod3]', mod1 === mod3); // ===> false
  console.log('[mod2 === mod3]', mod2 === mod3); // ===> false
}
{
  console.log('==== ViteDevServer.ssrLoadModule ====');
  const server = await createServer();
  const mod1 = await server.ssrLoadModule(fileUrl.href);
  const mod2 = await server.ssrLoadModule(fileUrl.href + '#bustCache=1');
  const mod3 = await server.ssrLoadModule(fileUrl.href + '?bustCache=1');
  console.log({ mod1, mod2, mod3 });
  console.log('[mod1 === mod2]', mod1 === mod2); // ===> true
  console.log('[mod1 === mod3]', mod1 === mod3); // ===> true
  console.log('[mod2 === mod3]', mod2 === mod3); // ===> true
  await server.close();
}

On Vite 5, file url was resolution failure. On Vite 6, it resolves but it looks like module identity is not considering hash/search. I only tested with ssrLoadModule entry case, but we should probably check other patterns too (static import, dynamic import, non-analyzable static import).

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-fchdscfz?file=repro.js

Steps to reproduce

  • open a stackblitz link and run node repro.js

System Info

(stackblitz)

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: latest => 6.0.11

Used Package Manager

npm

Logs

No response

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant