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

BUGFIX #6679 - workaround for tiny-lr not reloading on empty files arguments #6690

Merged
merged 1 commit into from
Feb 10, 2017

Conversation

jurecuhalev
Copy link
Contributor

In a situation when you revert failed compile attempt in broccoli-persistent-filter's processString,

// lib/tasks/server/livereload-server.js

didChange(results) {
...
      this.tree = new FSTree.fromEntries(this.getDirectoryEntries(results.directory), {sortAndExpand: true});
      files = previousTree.calculatePatch(this.tree)
        .filter(isNotRemoved)
        .filter(isNotDirectory)
        .map(relativePath)
        .filter(isNotSourceMapFile);

the result of files is [].

This gets passed to this.liveReloadServer().changed({ which doesn't trigger new websocket push, because there's nothing to notify clients about.

This PR works around this by catching the fact that there was a compilation error and forcing reload on next didChange.

I'm not sure if it's possible to write test for this as tiny-lr's changed doesn't return. I've got test written for the Error handling portion of the functionality.

This might be a too complicated approach, but I'm not familiar with whole system enough to see any other options. Because it doesn't different between reasons for errors, it also fixes #6242.

@stefanpenner
Copy link
Contributor

stefanpenner commented Jan 16, 2017

Let me summarize to make sure I understand this correctly (correct me if I mis-understand):

In-order to recover post error, if no files have changed (since we just restored to the original current state) we must reload anyways, as we are still on the error screen.

(if so, this seems reasonable)

this._hasCompileError = true;
files = ['LiveReload due to compile error'];
} else if ( this._hasCompileError) {
this._hasCompileError= false;
Copy link
Contributor

Choose a reason for hiding this comment

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

missing whitespace between _hasCompileError and =

@@ -137,8 +137,15 @@ class LiveReloadServerTask extends Task {
let previousTree = this.tree;
let files;

if ( results.stack ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

extra whitespace between ( and results.stack and );

if ( results.stack ) {
this._hasCompileError = true;
files = ['LiveReload due to compile error'];
} else if ( this._hasCompileError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

unbalanced whitespace

@jurecuhalev
Copy link
Contributor Author

@stefanpenner your understanding of the issue is correct

@jurecuhalev
Copy link
Contributor Author

I've fixed whitespace problems and squashed commits into single one.

@stefanpenner
Copy link
Contributor

@gandalfar thanks!

This looks reasonable, but we likely need a unit test covering it. If you need help, let me know. We can likely lend a hand if needed.

@jurecuhalev
Copy link
Contributor Author

Can you suggest what should be part of the test? I don't think I can capture tiny-lr output. I can assert against error stack trace and this._hasError.

@stefanpenner
Copy link
Contributor

likely just ensure https://github.com/ember-cli/ember-cli/pull/6690/files#diff-60cfa3bc4236a25e0793052851917a47R164 gets invoked with the expected value.

@jurecuhalev
Copy link
Contributor Author

I've added test that checks for changedCount and subject._hasCompileError. To actually track files contents, I'd have to modify

let stubbedChanged = function() {
      changedCount += 1;
    };

with custom changed method that tracks the value. I can do that if this is better approach (I was just looking at how other tests are written).

@jurecuhalev
Copy link
Contributor Author

I've squashed commits and made sure it still applies to current master. Is there anything else I can do?

@stefanpenner
Copy link
Contributor

@gandalfar this looks great! Sorry for letting this sit.

@stefanpenner
Copy link
Contributor

re-running appvevor, will merge when green.

@Turbo87
Copy link
Member

Turbo87 commented Feb 10, 2017

finally 🍏 !

@homu r+

@homu
Copy link
Contributor

homu commented Feb 10, 2017

📌 Commit 503ede1 has been approved by Turbo87

@homu
Copy link
Contributor

homu commented Feb 10, 2017

⌛ Testing commit 503ede1 with merge 352d6b1...

homu added a commit that referenced this pull request Feb 10, 2017
BUGFIX #6679 - workaround for tiny-lr not reloading on empty files arguments

In a situation when you revert failed compile attempt in `broccoli-persistent-filter`'s `processString`,

```
// lib/tasks/server/livereload-server.js

didChange(results) {
...
      this.tree = new FSTree.fromEntries(this.getDirectoryEntries(results.directory), {sortAndExpand: true});
      files = previousTree.calculatePatch(this.tree)
        .filter(isNotRemoved)
        .filter(isNotDirectory)
        .map(relativePath)
        .filter(isNotSourceMapFile);
```
the result of `files` is `[]`.

This gets passed to `this.liveReloadServer().changed({` which doesn't trigger new websocket push, because there's nothing to notify clients about.

This PR works around this by catching the fact that there was a compilation error and forcing reload on next `didChange`.

I'm not sure if it's possible to write test for this as `tiny-lr`'s [`changed`](https://github.com/mklabs/tiny-lr/blob/master/lib/server.js#L220) doesn't return. I've got test written for the Error handling portion of the functionality.

This might be a too complicated approach, but I'm not familiar with whole system enough to see any other options. Because it doesn't different between reasons for errors, it also fixes #6242.
@homu
Copy link
Contributor

homu commented Feb 10, 2017

☀️ Test successful - status

@homu homu merged commit 503ede1 into ember-cli:master Feb 10, 2017
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 this pull request may close these issues.

Fixing SASS error doesn't reload the page from build error
4 participants