Skip to content

Commit

Permalink
fix(dev/css): fix hmr for css referenced in html via <link>
Browse files Browse the repository at this point in the history
fix #469
  • Loading branch information
yyx990803 committed Jul 2, 2020
1 parent 1fa4d9a commit 202ee6e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ async function handleMessage(payload: HMRPayload) {
})
break
case 'style-update':
// check if this is referenced in html via <link>
const el = document.querySelector(`link[href*='${path}']`)
if (el) {
bustSwCache(path)
el.setAttribute(
'href',
`${path}${path.includes('?') ? '&' : '?'}t=${timestamp}`
)
break
}
// imported CSS
const importQuery = path.includes('?') ? '&import' : '?import'
bustSwCache(`${path}${importQuery}`)
await import(`${path}${importQuery}&t=${timestamp}`)
Expand Down

0 comments on commit 202ee6e

Please sign in to comment.