From 43ab1e9f86341e27967a71b591116a2f972e2797 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sun, 20 Sep 2020 07:33:09 -0700 Subject: [PATCH] fix duplicate CSS injection (#1536) --- CHANGELOG.md | 1 + src/core/create_compilers/RollupCompiler.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59deffd70..bb74c0f10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Minify and hash inject_styles.js [#1524](https://github.com/sveltejs/sapper/pull/1524) * Fix support for legacy browsers [#1525](https://github.com/sveltejs/sapper/pull/1525) * Fix flash of unstyled content [#1531](https://github.com/sveltejs/sapper/issues/1531) +* Fix duplicate CSS injection with both relative and absolute URLs [#1535](https://github.com/sveltejs/sapper/issues/1535) ## 0.28.7 diff --git a/src/core/create_compilers/RollupCompiler.ts b/src/core/create_compilers/RollupCompiler.ts index 6fc4d1910..8b0c15c75 100644 --- a/src/core/create_compilers/RollupCompiler.ts +++ b/src/core/create_compilers/RollupCompiler.ts @@ -25,7 +25,9 @@ const inject_styles = ` export default function(files) { return Promise.all(files.map(function(file) { return new Promise(function(fulfil, reject) { var href = new URL(file, import.meta.url); - var link = document.querySelector('link[rel=stylesheet][href="' + href + '"]'); + var relative = ('' + href).substring(document.baseURI.length); + var link = document.querySelector('link[rel=stylesheet][href="' + relative + '"]') + || document.querySelector('link[rel=stylesheet][href="' + href + '"]'); if (!link) { link = document.createElement('link'); link.rel = 'stylesheet';