Skip to content

Watch does not debounce restart when different files are updated within the debounce period #52721

@matthieusieben

Description

@matthieusieben

Version

v22.0.0

Platform

Darwin MacBook-Pro-de-Matthieu.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:25 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6030 arm64

Subsystem

watch

What steps will reproduce the bug?

  1. from a project that uses a lot of files (see snippet bellow)
  2. start the project with node --watch
  3. From another terminal touch multiple dependencies with a small sleep in between (for f in files/*; do touch $f; sleep 0.1; done)
  4. notice that Node restarts the program without applying debounce
Here is a script to set this up
// gen.mjs

import { writeFileSync, mkdirSync }from 'node:fs'
mkdirSync('./files', { recursive: true })
writeFileSync(`./files/0.mjs`, `export const log = (message) => console.log(message)`)
for (let i = 1; i < 100; i++) {
  writeFileSync(`./files/${i}.mjs`, `export { log } from './${i - 1}.mjs'`)
}

How often does it reproduce? Is there a required condition?

When using node --watch on a project that has live build (eg. tsc --watch), it happens very often as the typescript compiler seems to generate/update/touch lots of files, even when only one source file is updated.

What is the expected behavior? Why is that the expected behavior?

There is currently a debounce that prevent node from restarting the program when a single file file is updated in a short delay. This debounce should also happen when other files are updated within the same delay.

What do you see instead?

The debouncing behavior of watch does not apply when multiple files are updated

Additional information

Capture d’écran 2024-04-27 à 14 20 53

Metadata

Metadata

Assignees

No one assigned

    Labels

    watch-modeIssues and PRs related to watch mode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions