Skip to content

Commit aad2595

Browse files
authored
Merge pull request #1552 from BrowserSync/bugs/1550
bug fixes
2 parents b37e11c + 9cef9c1 commit aad2595

3 files changed

Lines changed: 34 additions & 7 deletions

File tree

client/vendor/Reloader.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {from} from "rxjs/observable/from";
1313
import {filter} from "rxjs/operators/filter";
1414
import {map} from "rxjs/operators/map";
1515
import {mergeMap} from "rxjs/operators/mergeMap";
16-
import {take} from "rxjs/operators/take";
1716
import {tap} from "rxjs/operators/tap";
1817
import {mapTo} from "rxjs/operators/mapTo";
1918
import {propSet} from "../lib/dom-effects/prop-set.dom-effect";
2019
import {styleSet} from "../lib/dom-effects/style-set.dom-effect";
2120
import {linkReplace} from "../lib/dom-effects/link-replace.dom-effect";
21+
import {mergeAll} from "rxjs/operators/mergeAll";
2222

2323
var hiddenElem;
2424

@@ -250,7 +250,7 @@ export function reload(document: Document, navigator: Navigator) {
250250
};
251251
}
252252

253-
function reattachStylesheetLink(link, document: Document, navigator: Navigator): Observable<any> {
253+
function reattachStylesheetLink(link: HTMLLinkElement, document: Document, navigator: Navigator): Observable<any> {
254254
// ignore LINKs that will be removed by LR soon
255255
let clone;
256256

@@ -291,10 +291,14 @@ export function reload(document: Document, navigator: Navigator) {
291291
additionalWaitingTime = 200;
292292
}
293293

294-
return Observable.create(obs => clone.onload = () => obs.next(true))
294+
return Observable.create(obs => {
295+
clone.onload = () => {
296+
obs.next(true);
297+
obs.complete()
298+
};
299+
})
295300
.pipe(
296-
take(1)
297-
, mergeMap(() => {
301+
mergeMap(() => {
298302
return timer(additionalWaitingTime)
299303
.pipe(
300304
tap(() => {
@@ -387,7 +391,7 @@ export function reload(document: Document, navigator: Navigator) {
387391

388392
function reloadStylesheet(path: string, document: Document, navigator): Observable<any> {
389393
// has to be a real array, because DOMNodeList will be modified
390-
const links = array(document.getElementsByTagName('link'))
394+
const links: HTMLLinkElement[] = array(document.getElementsByTagName('link'))
391395
.filter(link => {
392396
return link.rel.match(/^stylesheet$/i)
393397
&& !link.__LiveReload_pendingRemoval;
@@ -427,6 +431,15 @@ export function reload(document: Document, navigator: Navigator) {
427431
return reattachImportedRule(match.object, document);
428432
}
429433
return reattachStylesheetLink(match.object, document, navigator);
434+
} else {
435+
if (links.length) {
436+
// no <link> elements matched, so was the path including '*'?
437+
const [first, ...rest] = path.split('.');
438+
if (first === '*') {
439+
return from(links.map(link => reattachStylesheetLink(link, document, navigator)))
440+
.pipe(mergeAll())
441+
}
442+
}
430443
}
431444

432445
return empty();

client/webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module.exports = {
1313
path: path.join.apply(null, context.concat("dist")),
1414
filename: 'index.js',
1515
},
16-
devtool: "source-map",
1716
plugins: [
1817
// new webpack.NoEmitOnErrorsPlugin(),
1918
],

cypress/integration/file-reloading.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ describe('Reloading files', function() {
1919
});
2020
});
2121
});
22+
it('should reload with *.css', function() {
23+
cy.get('#__bs_notify__').should('have.length', 1);
24+
cy.request('POST', 'http://localhost:3000/__browser_sync__',
25+
JSON.stringify([
26+
"file:reload",
27+
{"ext":"css","path":"*.css","basename":"*/*.css","event":"change","type":"inject","log":true}
28+
])
29+
);
30+
cy.get('link').should($links => {
31+
$links.each((i, elem) => {
32+
const url = new URL(elem.href);
33+
return expect(url.search).to.contain('?browsersync=');
34+
});
35+
});
36+
});
2237
});
2338
context('CSS IMPORTS', function() {
2439
it('can import 1 stylesheet from <style>@import</style>', () => {

0 commit comments

Comments
 (0)