Skip to content

Commit

Permalink
fix: invalidate inlined proxy scripts on change (#5891)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored Dec 2, 2021
1 parent 65807ae commit 5b8c58b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/vite/src/node/server/middlewares/indexHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,20 @@ const devHtmlHook: IndexHtmlTransformHook = async (
addToHTMLProxyCache(config, url, scriptModuleIndex, contents)

// inline js module. convert to src="proxy"
const modulePath = `${
config.base + htmlPath.slice(1)
}?html-proxy&index=${scriptModuleIndex}.js`

// invalidate the module so the newly cached contents will be served
const module = server?.moduleGraph.getModuleById(modulePath)
if (module) {
server?.moduleGraph.invalidateModule(module)
}

s.overwrite(
node.loc.start.offset,
node.loc.end.offset,
`<script type="module" src="${
config.base + url.slice(1)
}?html-proxy&index=${scriptModuleIndex}.js"></script>`
`<script type="module" src="${modulePath}"></script>`
)
}
}
Expand Down

0 comments on commit 5b8c58b

Please sign in to comment.