Fix cached inline modules (#2038)
* Fix cached inline modules * Adds a changeset
This commit is contained in:
parent
fad6bd0936
commit
341ec3cdfd
2 changed files with 17 additions and 2 deletions
7
.changeset/little-carrots-sleep.md
Normal file
7
.changeset/little-carrots-sleep.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes dev errors in hydrated components
|
||||
|
||||
The errors would occur when there was state changes in hydrated components. This only occurs in dev but does result in the hydrated component not working. This fixes the underlying issue.
|
|
@ -56982,8 +56982,10 @@ const devHtmlHook = async (html, { path: htmlPath, server, originalUrl }) => {
|
|||
.join('');
|
||||
// add HTML Proxy to Map
|
||||
addToHTMLProxyCache(config, url, scriptModuleIndex, contents);
|
||||
// inline js module. convert to src="proxy"
|
||||
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>`);
|
||||
const modulePath = `${config.base + htmlPath.slice(1)}?html-proxy&index=${scriptModuleIndex}.js`;
|
||||
// invalidate the module so the newly cached contents will be served
|
||||
server === null || server === void 0 ? void 0 : server.moduleGraph.invalidateId(config.root + modulePath);
|
||||
s.overwrite(node.loc.start.offset, node.loc.end.offset, `<script type="module" src="${modulePath}"></script>`);
|
||||
}
|
||||
}
|
||||
// elements with [href/src] attrs
|
||||
|
@ -57113,6 +57115,12 @@ class ModuleGraph {
|
|||
mod.ssrTransformResult = null;
|
||||
invalidateSSRModule(mod, seen);
|
||||
}
|
||||
invalidateId(id) {
|
||||
const mod = this.idToModuleMap.get(id);
|
||||
if (mod) {
|
||||
this.invalidateModule(mod);
|
||||
}
|
||||
}
|
||||
invalidateAll() {
|
||||
const seen = new Set();
|
||||
this.idToModuleMap.forEach((mod) => {
|
||||
|
|
Loading…
Reference in a new issue