Skip to content

transformRequest can leave transformResult as null when called right after invalidateModule #19804

@hi-ogawa

Description

@hi-ogawa

Describe the bug

Providing a proper reproduction for the issue discussed in #19790 (comment)

  const server = await createServer({ configFile: false });
  const environment = server.environments.ssr;
  const url = `/repro-entry.js`;
  const id = path.resolve('repro-entry.js');

  {
    await environment.transformRequest(url);
    const mod = environment.moduleGraph.getModuleById(id);
    console.log('[1st transformResult]', mod.transformResult); // => (ok)
  }

  environment.moduleGraph.invalidateAll();

  {
    // `transformRequest` immediately after `invalidateAll` skips setting `mod.transformResult`.
    await environment.transformRequest(url);
    const mod = environment.moduleGraph.getModuleById(id);
    console.log('[2nd transformResult]', mod.transformResult); // => null
  }

This is due to 2nd transformRequest's timestamp and lastInvalidationTimestamp happens at the same millisecond.

if (timestamp > mod.lastInvalidationTimestamp)
moduleGraph.updateModuleTransformResult(mod, result)

I think changing condition into timestamp >= mod.lastInvalidationTimestamp is not right either since it can lead to stale when transformRequest and invalidateAll happens at the same time (cf. #7254).

Reproduction

https://stackblitz.com/edit/vitejs-vite-bgq6kwfo?file=repro.js

Steps to reproduce

No response

System Info

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: ^6.2.2 => 6.2.5

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions