Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HMR propagation of HTML changes (fix #7870) #7895

Merged
merged 3 commits into from Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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')
})
}
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