Skip to content

Commit

Permalink
chore: omit the fix for double stylesheets loading
Browse files Browse the repository at this point in the history
The reason is that it's already fixed by vitejs#9970, and we want to make this PR independent.
  • Loading branch information
Tal500 committed Sep 18, 2022
1 parent 94908e1 commit 1f05b29
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Expand Up @@ -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<HTMLLinkElement>(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
}

Expand Down

0 comments on commit 1f05b29

Please sign in to comment.