Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: disable hmr for tags api #188

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading