Skip to content

fix: NativeWatchFileSystem should handle inputFileSystem when files change #11164

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

GiveMe-A-Name
Copy link
Member

@GiveMe-A-Name GiveMe-A-Name commented Jul 24, 2025

Summary

What This PR Does

This PR fixes a critical bug in Rspack's NativeWatchFileSystem where it wasn't properly handling the inputFileSystem cache invalidation when files change during watch mode, leading to stale cached file contents and incorrect build behavior.

Key Issues Fixed

  1. Cache Invalidation Bug
    Problem: When files changed during watch mode, the inputFileSystem cache wasn't being purged, causing the compiler to use outdated file contents
    Solution: Added proper cache purging logic that calls fs.purge?.(item) for both changed and removed files
  2. Watcher Executor Loop Issue
    Problem: In the Rust watcher executor, when the file list was empty, the function would return instead of continue, causing the watch loop to exit prematurely
    Solution: Changed return to continue to keep the watcher loop running even when no files are pending

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@Copilot Copilot AI review requested due to automatic review settings July 24, 2025 10:10
@GiveMe-A-Name GiveMe-A-Name requested a review from hardfist as a code owner July 24, 2025 10:10
@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Jul 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the NativeWatchFileSystem to properly handle the inputFileSystem when files change during watch mode. The fix ensures that the file system cache is properly purged when files are modified or removed, preventing stale cached data from being used.

Key changes:

  • Modified NativeWatchFileSystem constructor to accept and store an inputFileSystem parameter
  • Added cache purging logic to clear cached file data when files change or are removed
  • Fixed a potential infinite loop in the Rust watcher executor by changing return to continue
  • Added comprehensive test coverage for the native watcher functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/rspack/src/node/NodeEnvironmentPlugin.ts Updated to pass inputFileSystem parameter to NativeWatchFileSystem constructor
packages/rspack/src/NativeWatchFileSystem.ts Added constructor parameter and cache purging logic for changed/removed files
crates/rspack_fs/src/watcher/executor.rs Fixed potential infinite loop by changing return to continue in empty files condition
tests/webpack-test/jest.config.js Enabled new native watcher test cases in Jest configuration
tests/webpack-test/NativeWatcherTestCases.longtest.js Added new test file for native watcher functionality

Copy link

netlify bot commented Jul 24, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit c2f5f9c
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6883523d3955b400088ca966
😎 Deploy Preview https://deploy-preview-11164--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

github-actions bot commented Jul 24, 2025

📦 Binary Size-limit

Comparing c2f5f9c to chore: upgrade rspack_resolver to 0.6.1 (#11175) by pshu

❌ Size increased by 128bytes from 49.00MB to 49.00MB (⬆️0.00%)

Copy link

codspeed-hq bot commented Jul 24, 2025

CodSpeed Performance Report

Merging #11164 will not alter performance

Comparing fix/native-watcher (c2f5f9c) with main (e9e5acc)

🎉 Hooray! codspeed-node just leveled up to 4.0.1!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 16 untouched benchmarks

@GiveMe-A-Name GiveMe-A-Name marked this pull request as draft July 24, 2025 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant