Skip to content

Commit

Permalink
fix: arc integration caching issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Nov 30, 2023
1 parent d326a8e commit a09d7e3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-shirts-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Fix caching issue with virtual Marko files created by arc
4 changes: 3 additions & 1 deletion src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ before(async () => {
context.exposeFunction("__track__", (html: string) => {
const formatted = defaultSerializer(
defaultNormalizer(JSDOM.fragment(html)),
).replace(/-[a-z0-9]+(\.\w+)/i, "-[hash]$1");
)
.replace(/-[a-z0-9]+(\.\w+)/i, "-[hash]$1")
.replace(/[?&][tv]=[\d.]+/, "");

if (changes.at(-1) !== formatted) {
changes.push(formatted);
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const virtualFiles = new Map<
string,
VirtualFile | DeferredPromise<VirtualFile>
>();
const extReg = /\.[^.]+$/;
const queryReg = /\?marko-[^?]+$/;
const browserEntryQuery = "?marko-browser-entry";
const serverEntryQuery = "?marko-server-entry";
Expand Down Expand Up @@ -551,8 +552,12 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
async transform(source, rawId, ssr) {
let id = stripVersionAndTimeStamp(rawId);
const info = isBuild ? this.getModuleInfo(id) : undefined;
if (info?.meta.arcSourceId) {
id = info.meta.arcSourceId;
const arcSourceId = info?.meta.arcSourceId;
if (arcSourceId) {
const arcFlagSet = info.meta.arcFlagSet;
id = arcFlagSet
? arcSourceId.replace(extReg, `[${arcFlagSet.join("+")}]$&`)
: arcSourceId;
}

const isSSR = typeof ssr === "object" ? ssr.ssr : ssr;
Expand Down

0 comments on commit a09d7e3

Please sign in to comment.