From 1f05b290549cf39d9e121e4e446c40276a7bf4e6 Mon Sep 17 00:00:00 2001 From: Tal Hadad Date: Sun, 18 Sep 2022 15:26:17 +0300 Subject: [PATCH] chore: omit the fix for double stylesheets loading The reason is that it's already fixed by #9970, and we want to make this PR independent. --- .../src/node/plugins/importAnalysisBuild.ts | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 1c13581fb69133..6927b564186e51 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -75,23 +75,8 @@ function preload( seen[dep] = true const isCss = dep.endsWith('.css') const cssSelector = isCss ? '[rel="stylesheet"]' : '' - const isBaseRelative = !!importerUrl - - // check if the file is already preloaded by SSR markup - if (isBaseRelative) { - const separatorIdx = dep.lastIndexOf('/') - const shortDep = separatorIdx < 0 ? dep : dep.slice(separatorIdx + 1) - const linkSelector = `link[href$="${shortDep}"]${cssSelector}` - const links = document.querySelectorAll(linkSelector) - - for (let i = links.length - 1; i >= 0; i--) { - // When isBaseRelative is true then we have importerUrl and `dep` is - // already converted to an absolute URL by the assetsURL function. The - // `link.href` also has an absolute URL thanks to browser doing the - // work for us. See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:idl-domstring-5 - if (links[i].href === dep) return - } - } else if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) { + // @ts-ignore check if the file is already preloaded by SSR markup + if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) { return }