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

.addWatchFiles() dependencies can fail to trigger rebuilds in 1.21.0+ #3111

Closed
tivac opened this issue Sep 12, 2019 · 0 comments · Fixed by #3112
Closed

.addWatchFiles() dependencies can fail to trigger rebuilds in 1.21.0+ #3111

tivac opened this issue Sep 12, 2019 · 0 comments · Fixed by #3112

Comments

@tivac
Copy link
Contributor

tivac commented Sep 12, 2019

  • Rollup Version: 1.21.0 and higher
  • Operating System (or Browser): Windows 10
  • Node Version: 12.8.0

How Do We Reproduce?

https://gist.github.com/tivac/ca2ff933d6dac4e06e8264800b0a1f98

Expected Behavior

Dependencies expressed using this.addWatchFile() would trigger invalidation of the calling module whenever the dependency changes.

Actual Behavior

The calling module is not invalidated.

Bug explanation

This bug was introduced by #3081 (which is an awesome change and a huge QoL improvement), but just cost me an evening chasing down a subtle issue.

Here's the specific problematic change.

invalidate(id: string, isTransformDependency: boolean) {
    this.invalidated = true;
    if (isTransformDependency) {
-        (this.cache.modules as ModuleJSON[]).forEach(module => {
-            if (!module.transformDependencies || module.transformDependencies.indexOf(id) === -1)
-                return;
+        for (const module of this.cache.modules) {
+            if (module.transformDependencies.indexOf(id) === -1) return;
            // effective invalidation
            module.originalCode = null as any;
-        });
+        }
    }
    this.watcher.invalidate(id);
}

When this code was refactored from this.cache.modules.forEach(..) to for(const module of this.cache.modules) { ... }, the return wasn't changed to a continue, so as soon as the first module that doesn't have a matching id in transformDependencies is found it halts iteration.

tivac added a commit to tivac/rollup that referenced this issue Sep 12, 2019
instead of using return and having it end the entire function invocation.

Fixes rollup#3111
tivac added a commit to tivac/modular-css that referenced this issue Sep 12, 2019
Can't go to anything later due to rollup/rollup#3111
@tivac tivac changed the title .addWatchFiles don't always trigger rebuilds in 1.21.0+ .addWatchFiles() dependencies can fail to trigger rebuilds in 1.21.0+ Sep 13, 2019
lukastaegert pushed a commit that referenced this issue Sep 14, 2019
…3112)

* fix: use continue to end the loop iteration

instead of using return and having it end the entire function invocation.

Fixes #3111

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

Successfully merging a pull request may close this issue.

1 participant