Skip to content

Commit

Permalink
chore: disable hmr for tags api (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Jan 16, 2025
1 parent ff8a2fe commit e719cab
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-fireants-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Temporarily disable hmr for tags api projects (hmr is pending implementation for tags api).
54 changes: 30 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
let serverManifest: ServerManifest | undefined;
let basePath = "/";
let getMarkoAssetFns: undefined | API.getMarkoAssetCodeForEntry[];
let tagsAPI: undefined | boolean;
const entryIds = new Set<string>();
const cachedSources = new Map<string, string>();
const transformWatchFiles = new Map<string, string[]>();
Expand All @@ -161,6 +160,34 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
`vite-marko${runtimeId ? `-${runtimeId}` : ""}`,
);

const isTagsApi = (() => {
let tagsAPI: undefined | boolean;
return () => {
if (tagsAPI === undefined) {
const translatorPackage =
opts.translator ||
compiler.globalConfig?.translator ||
"marko/translator";
if (
/^@marko\/translator-(?:default|interop-class-tags)$/.test(
translatorPackage,
)
) {
tagsAPI = false;
} else {
try {
const require = createRequire(import.meta.url);
tagsAPI = require(translatorPackage).preferAPI !== "class";
} catch {
tagsAPI = true;
}
}
}

return tagsAPI;
};
})();

return [
{
name: "marko-vite:pre",
Expand Down Expand Up @@ -654,33 +681,12 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
}
}

if (tagsAPI === undefined) {
const translatorPackage =
opts.translator ||
compiler.globalConfig?.translator ||
"marko/translator";
if (
/^@marko\/translator-(?:default|interop-class-tags)$/.test(
translatorPackage,
)
) {
tagsAPI = false;
} else {
try {
const require = createRequire(import.meta.url);
tagsAPI = require(translatorPackage).preferAPI !== "class";
} catch {
tagsAPI = true;
}
}
}

source = await getServerEntryTemplate({
fileName,
entryData,
runtimeId,
basePathVar: isBuild ? basePathVar : undefined,
tagsAPI,
tagsAPI: isTagsApi(),
});
}
}
Expand Down Expand Up @@ -750,7 +756,7 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
const { map, meta } = compiled;
let { code } = compiled;

if (query !== browserEntryQuery && devServer) {
if (query !== browserEntryQuery && devServer && !isTagsApi()) {
code += `\nif (import.meta.hot) import.meta.hot.accept(() => {});`;
}

Expand Down

0 comments on commit e719cab

Please sign in to comment.