File tree Expand file tree Collapse file tree 4 files changed +29
-1
lines changed
packages/vite/src/node/server Expand file tree Collapse file tree 4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -690,7 +690,12 @@ export function updateModules(
690690
691691 // html file cannot be hot updated
692692 const isClientHtmlChange =
693- file . endsWith ( '.html' ) && environment . name === 'client'
693+ file . endsWith ( '.html' ) &&
694+ environment . name === 'client' &&
695+ // if the html file is imported as a module, we assume that this file is
696+ // not used as the template for top-level request response
697+ // (i.e. not used by the middleware).
698+ modules . every ( ( mod ) => mod . type !== 'js' )
694699
695700 if ( needFullReload || isClientHtmlChange ) {
696701 const reason =
Original file line number Diff line number Diff line change 11import path from 'node:path'
2+ import { stripVTControlCharacters } from 'node:util'
23import { describe , expect , test } from 'vitest'
34import {
45 browserLogs ,
@@ -463,6 +464,20 @@ test('Unknown extension assets import', async () => {
463464
464465test ( '?raw import' , async ( ) => {
465466 expect ( await page . textContent ( '.raw' ) ) . toMatch ( 'SVG' )
467+ expect ( await page . textContent ( '.raw-html' ) ) . toBe ( '<div>partial</div>\n' )
468+
469+ if ( isBuild ) return
470+ editFile ( 'nested/partial.html' , ( code ) =>
471+ code . replace ( '<div>partial</div>' , '<div>partial updated</div>' ) ,
472+ )
473+ await expect
474+ . poll ( ( ) => page . textContent ( '.raw-html' ) )
475+ . toBe ( '<div>partial updated</div>\n' )
476+ expect ( browserLogs ) . toStrictEqual (
477+ expect . arrayContaining ( [
478+ expect . stringContaining ( 'hot updated: /nested/partial.html?raw via' ) ,
479+ ] ) ,
480+ )
466481} )
467482
468483test ( '?no-inline svg import' , async ( ) => {
Original file line number Diff line number Diff line change @@ -265,6 +265,7 @@ <h2>Unknown extension assets import</h2>
265265
266266< h2 > ?raw import</ h2 >
267267< code class ="raw "> </ code >
268+ < code class ="raw-html "> </ code >
268269
269270< h2 > ?no-inline svg import</ h2 >
270271< code class ="no-inline-svg "> </ code >
@@ -546,6 +547,12 @@ <h3>assets in template</h3>
546547 import rawSvg from './nested/fragment.svg?raw'
547548 text ( '.raw' , rawSvg )
548549
550+ import rawHtml from './nested/partial.html?raw'
551+ text ( '.raw-html' , rawHtml )
552+ import . meta. hot ?. accept ( './nested/partial.html?raw' , ( m ) => {
553+ text ( '.raw-html' , m . default )
554+ } )
555+
549556 import noInlineSvg from './nested/fragment.svg?no-inline'
550557 text ( '.no-inline-svg' , noInlineSvg )
551558
Original file line number Diff line number Diff line change 1+ < div > partial</ div >
You can’t perform that action at this time.
0 commit comments