Skip to content

Commit fa7e791

Browse files
committed
fix(css-injection): enable smoother CSS file for none-css files - re: #1488
1 parent 2ccd8ac commit fa7e791

5 files changed

Lines changed: 71 additions & 41 deletions

File tree

client/dist/index.js

Lines changed: 34 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/dist/index.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/dist/index.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/vendor/Reloader.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class Reloader {
9393
const elems = Reloader.getMatches(domData.elems, data.basename, domData.attr);
9494

9595
for (var i = 0, n = elems.length; i < n; i += 1) {
96-
this.swapFile(elems[i], domData.attr, options);
96+
this.swapFile(elems[i], domData, options);
9797
}
9898

9999
(cb || function() {})(elems, domData);
@@ -102,8 +102,9 @@ export class Reloader {
102102
const tagName = options.tagNames[fileExtension];
103103
const attr = options.attrs[tagName];
104104
return {
105-
elems: document.getElementsByTagName(tagName),
106-
attr: attr
105+
attr,
106+
tagName,
107+
elems: document.getElementsByTagName(tagName)
107108
};
108109
}
109110

@@ -125,32 +126,46 @@ export class Reloader {
125126
return matches;
126127
};
127128

128-
public swapFile(elem, attr, options) {
129+
public swapFile(elem, domData, options) {
129130

131+
const attr = domData.attr;
130132
const currentValue = elem[attr];
131133
const timeStamp = new Date().getTime();
132134
const key = "browsersync-legacy";
133135
const suffix = key + "=" + timeStamp;
134136
const anchor = getLocation(currentValue);
135137
const search = updateSearch(anchor.search, key, suffix);
136138

137-
if (options.timestamps === false) {
138-
elem[attr] = anchor.href;
139-
} else {
140-
elem[attr] = anchor.href.split("?")[0] + search;
141-
}
139+
switch (domData.tagName) {
140+
case 'link': {
141+
this.logger.trace(`replacing LINK ${attr}`);
142+
this.reloadStylesheet(currentValue);
143+
break;
144+
}
145+
case 'img': {
146+
this.reloadImages(currentValue);
147+
break;
148+
}
149+
default: {
150+
if (options.timestamps === false) {
151+
elem[attr] = anchor.href;
152+
} else {
153+
elem[attr] = anchor.href.split("?")[0] + search;
154+
}
142155

143-
this.logger.info(`reloading ${elem[attr]}`);
156+
this.logger.info(`reloading ${elem[attr]}`);
144157

145-
setTimeout(function () {
146-
if (!hiddenElem) {
147-
hiddenElem = document.createElement("DIV");
148-
document.body.appendChild(hiddenElem);
149-
} else {
150-
hiddenElem.style.display = "none";
151-
hiddenElem.style.display = "block";
158+
setTimeout(function () {
159+
if (!hiddenElem) {
160+
hiddenElem = document.createElement("DIV");
161+
document.body.appendChild(hiddenElem);
162+
} else {
163+
hiddenElem.style.display = "none";
164+
hiddenElem.style.display = "block";
165+
}
166+
}, 200);
152167
}
153-
}, 200);
168+
}
154169

155170
return {
156171
elem: elem,

0 commit comments

Comments
 (0)