Skip to content

Commit f957956

Browse files
committed
fix(client): regression over injection of extensions declared under config.injectFileTypes
Added a fallback to legacy behaviour to account for this - fixes #1488
1 parent 55127fe commit f957956

9 files changed

Lines changed: 312 additions & 18 deletions

File tree

client/dist/index.js

Lines changed: 125 additions & 5 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/lib/code-sync.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ const log = nanlogger("Browsersync", { colors: { magenta: "#0F2634" } });
1010
const reloader = new Reloader(window, log, Timer);
1111

1212
const options = {
13+
tagNames: {
14+
"css": "link",
15+
"jpg": "img",
16+
"jpeg": "img",
17+
"png": "img",
18+
"svg": "img",
19+
"gif": "img",
20+
"js": "script"
21+
},
22+
attrs: {
23+
"link": "href",
24+
"img": "src",
25+
"script": "src"
26+
},
1327
blacklist: [
1428
// never allow .map files through
1529
function(incoming) {
@@ -27,6 +41,11 @@ const current = function() {
2741
* @param {BrowserSync} bs
2842
*/
2943
sync.init = function(bs) {
44+
45+
if (bs.options.tagNames) {
46+
options.tagNames = bs.options.tagNames;
47+
}
48+
3049
if (bs.options.scrollRestoreTechnique === "window.name") {
3150
sync.saveScrollInName(emitter);
3251
} else {
@@ -136,18 +155,21 @@ sync.reload = function(bs) {
136155
return;
137156
}
138157

139-
var options = bs.options;
140-
141-
if (data.url || !options.injectChanges) {
158+
if (data.url || !bs.options.injectChanges) {
142159
sync.reloadBrowser(true);
143160
}
144161

145162
if (data.basename && data.ext) {
163+
146164
if (sync.isBlacklisted(data)) {
147165
return;
148166
}
149167

150-
reloader.reload(data.path, { liveCSS: true, liveImg: true });
168+
reloader.reload(data, {
169+
...options,
170+
liveCSS: true,
171+
liveImg: true
172+
});
151173
}
152174
};
153175
};

client/lib/utils.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,41 @@ export const numberOfMatchingSegments = function(path1, path2) {
7676

7777
export const pathsMatch = (path1, path2) =>
7878
numberOfMatchingSegments(path1, path2) > 0;
79+
80+
export function getLocation(url: string) {
81+
var location = document.createElement("a");
82+
location.href = url;
83+
84+
if (location.host === "") {
85+
location.href = location.href;
86+
}
87+
88+
return location;
89+
}
90+
91+
/**
92+
* @param {string} search
93+
* @param {string} key
94+
* @param {string} suffix
95+
*/
96+
export function updateSearch(search, key, suffix) {
97+
98+
if (search === "") {
99+
return "?" + suffix;
100+
}
101+
102+
return "?" + search
103+
.slice(1)
104+
.split("&")
105+
.map(function (item) {
106+
return item.split("=");
107+
})
108+
.filter(function (tuple) {
109+
return tuple[0] !== key;
110+
})
111+
.map(function (item) {
112+
return [item[0], item[1]].join("=");
113+
})
114+
.concat(suffix)
115+
.join("&");
116+
};

0 commit comments

Comments
 (0)