Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: HMR propagation of HTML changes (fix #7870) (#7895)
  • Loading branch information
brillout committed Apr 25, 2022
1 parent ecc78bc commit 1f7855c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/playground/hmr/__tests__/hmr.spec.ts
Expand Up @@ -162,15 +162,15 @@ if (!isBuild) {
})

test('not loaded dynamic import', async () => {
await page.goto(viteTestUrl + '/dynamic-import/index.html')
await page.goto(viteTestUrl + '/counter/index.html')

let btn = await page.$('button')
expect(await btn.textContent()).toBe('Counter 0')
await btn.click()
expect(await btn.textContent()).toBe('Counter 1')

// Modifying `index.ts` triggers a page reload, as expected
editFile('dynamic-import/index.ts', (code) => code)
editFile('counter/index.ts', (code) => code)
await page.waitForNavigation()
btn = await page.$('button')
expect(await btn.textContent()).toBe('Counter 0')
Expand All @@ -184,7 +184,7 @@ if (!isBuild) {
// (Note that, a dynamic import that is never loaded and that does not
// define `accept.module.hot.accept` may wrongfully trigger a full page
// reload, see discussion at #7561.)
editFile('dynamic-import/dep.ts', (code) => code)
editFile('counter/dep.ts', (code) => code)
try {
await page.waitForNavigation({ timeout: 1000 })
} catch (err) {
Expand All @@ -194,4 +194,16 @@ if (!isBuild) {
btn = await page.$('button')
expect(await btn.textContent()).toBe('Counter 1')
})

test('HTML', async () => {
await page.goto(viteTestUrl + '/counter/index.html')
let btn = await page.$('button')
expect(await btn.textContent()).toBe('Counter 0')
editFile('counter/index.html', (code) =>
code.replace('Counter', 'Compteur')
)
await page.waitForNavigation()
btn = await page.$('button')
expect(await btn.textContent()).toBe('Compteur 0')
})
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions packages/vite/src/node/server/moduleGraph.ts
Expand Up @@ -2,6 +2,7 @@ import { extname } from 'path'
import type { ModuleInfo, PartialResolvedId } from 'rollup'
import { parse as parseUrl } from 'url'
import { isDirectCSSRequest } from '../plugins/css'
import { isHTMLRequest } from '../plugins/html'
import {
cleanUrl,
normalizePath,
Expand Down Expand Up @@ -37,6 +38,12 @@ export class ModuleNode {
constructor(url: string) {
this.url = url
this.type = isDirectCSSRequest(url) ? 'css' : 'js'
// #7870
// The `isSelfAccepting` value is set by importAnalysis, but HTML
// assets don't go through importAnalysis.
if (isHTMLRequest(url)) {
this.isSelfAccepting = false
}
}
}

Expand Down

0 comments on commit 1f7855c

Please sign in to comment.