diff --git a/plugins/twind/shared.ts b/plugins/twind/shared.ts
index b01e2f5f..4caa81d6 100644
--- a/plugins/twind/shared.ts
+++ b/plugins/twind/shared.ts
@@ -43,6 +43,7 @@ export function setup(options: Options, sheet: Sheet) {
}
if (props.className) {
classes.push(tw(props.className));
+ props.className = undefined;
}
if (classes.length) {
props.class = classes.join(" ");
diff --git a/plugins/twindv1/shared.ts b/plugins/twindv1/shared.ts
index 39816353..0e3e9934 100644
--- a/plugins/twindv1/shared.ts
+++ b/plugins/twindv1/shared.ts
@@ -38,6 +38,7 @@ export function setup({ selfURL: _selfURL, ...config }: Options, sheet: Sheet) {
}
if (props.className) {
classes.push(tw(props.className));
+ props.className = undefined;
}
if (classes.length) {
props.class = classes.join(" ");
diff --git a/tests/fixture_twind_app/deno.json b/tests/fixture_twind_app/deno.json
new file mode 100644
index 00000000..c4df0177
--- /dev/null
+++ b/tests/fixture_twind_app/deno.json
@@ -0,0 +1,20 @@
+{
+ "lock": false,
+ "tasks": {
+ "start": "deno run -A --watch=static/,routes/ dev.ts"
+ },
+ "imports": {
+ "$fresh/": "../../",
+ "twind": "https://esm.sh/twind@0.16.19",
+ "twind/": "https://esm.sh/twind@0.16.19/",
+ "preact": "https://esm.sh/preact@10.15.1",
+ "preact/": "https://esm.sh/preact@10.15.1/",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.1.0",
+ "@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
+ "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
+ },
+ "compilerOptions": {
+ "jsx": "react-jsx",
+ "jsxImportSource": "preact"
+ }
+}
diff --git a/tests/fixture_twind_app/dev.ts b/tests/fixture_twind_app/dev.ts
new file mode 100755
index 00000000..2d85d6c1
--- /dev/null
+++ b/tests/fixture_twind_app/dev.ts
@@ -0,0 +1,5 @@
+#!/usr/bin/env -S deno run -A --watch=static/,routes/
+
+import dev from "$fresh/dev.ts";
+
+await dev(import.meta.url, "./main.ts");
diff --git a/tests/fixture_twind_app/fresh.gen.ts b/tests/fixture_twind_app/fresh.gen.ts
new file mode 100644
index 00000000..690567f8
--- /dev/null
+++ b/tests/fixture_twind_app/fresh.gen.ts
@@ -0,0 +1,19 @@
+// DO NOT EDIT. This file is generated by Fresh.
+// This file SHOULD be checked into source version control.
+// This file is automatically updated during development when running `dev.ts`.
+
+import * as $0 from "./routes/_app.tsx";
+import * as $1 from "./routes/app_class.tsx";
+import * as $2 from "./routes/index.tsx";
+
+const manifest = {
+ routes: {
+ "./routes/_app.tsx": $0,
+ "./routes/app_class.tsx": $1,
+ "./routes/index.tsx": $2,
+ },
+ islands: {},
+ baseUrl: import.meta.url,
+};
+
+export default manifest;
diff --git a/tests/fixture_twind_app/main.ts b/tests/fixture_twind_app/main.ts
new file mode 100644
index 00000000..81b6ecb5
--- /dev/null
+++ b/tests/fixture_twind_app/main.ts
@@ -0,0 +1,18 @@
+///
+///
+///
+///
+
+import { start } from "$fresh/server.ts";
+import twind from "$fresh/plugins/twind.ts";
+import twindV1 from "$fresh/plugins/twindv1.ts";
+import manifest from "./fresh.gen.ts";
+
+const twindPlugin = Deno.env.has("TWIND_V1")
+ ? twindV1({
+ selfURL: import.meta.url,
+ // deno-lint-ignore no-explicit-any
+ } as any)
+ : twind({ selfURL: import.meta.url });
+
+await start(manifest, { plugins: [twindPlugin] });
diff --git a/tests/fixture_twind_app/routes/_app.tsx b/tests/fixture_twind_app/routes/_app.tsx
new file mode 100644
index 00000000..5183eaa7
--- /dev/null
+++ b/tests/fixture_twind_app/routes/_app.tsx
@@ -0,0 +1,16 @@
+import { AppProps } from "$fresh/server.ts";
+
+export default function App({ Component }: AppProps) {
+ return (
+
+
+
+
+ fresh-foo
+
+
+
+
+
+ );
+}
diff --git a/tests/fixture_twind_app/routes/app_class.tsx b/tests/fixture_twind_app/routes/app_class.tsx
new file mode 100644
index 00000000..5048322b
--- /dev/null
+++ b/tests/fixture_twind_app/routes/app_class.tsx
@@ -0,0 +1,3 @@
+export default function Page() {
+ return it works
;
+}
diff --git a/tests/fixture_twind_app/routes/index.tsx b/tests/fixture_twind_app/routes/index.tsx
new file mode 100644
index 00000000..b507958e
--- /dev/null
+++ b/tests/fixture_twind_app/routes/index.tsx
@@ -0,0 +1,27 @@
+import * as path from "https://deno.land/std@0.192.0/path/mod.ts";
+
+const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
+
+const links: string[] = [];
+for (const file of Deno.readDirSync(__dirname)) {
+ if (file.name.startsWith("index")) continue;
+ const name = path.basename(file.name, path.extname(file.name));
+ links.push(name);
+}
+
+export default function Home() {
+ return (
+
+
Tests
+
+ {links.map((link) => {
+ return (
+ -
+ {link}
+
+ );
+ })}
+
+
+ );
+}
diff --git a/tests/test_utils.ts b/tests/test_utils.ts
index 40dd446a..d2da7520 100644
--- a/tests/test_utils.ts
+++ b/tests/test_utils.ts
@@ -128,11 +128,22 @@ function _printDomNode(
}
export async function withFresh(
- name: string,
+ name: string | { name: string; options: Omit },
fn: (address: string) => Promise,
) {
+ let file: string;
+ let options = {};
+
+ if (typeof name === "object") {
+ file = name.name;
+ options = name.options ?? {};
+ } else {
+ file = name;
+ }
+
const { lines, serverProcess, address } = await startFreshServer({
- args: ["run", "-A", name],
+ ...options,
+ args: ["run", "-A", file],
});
try {
diff --git a/tests/twind_test.ts b/tests/twind_test.ts
index 741ff8c4..5db357af 100644
--- a/tests/twind_test.ts
+++ b/tests/twind_test.ts
@@ -1,7 +1,7 @@
-import { assert, assertEquals, delay, puppeteer } from "./deps.ts";
+import { assert, assertEquals, assertMatch, delay, puppeteer } from "./deps.ts";
import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
-import { startFreshServer, withPageName } from "./test_utils.ts";
+import { startFreshServer, withFresh, withPageName } from "./test_utils.ts";
/**
* Start the server with the main file.
@@ -350,3 +350,50 @@ Deno.test({
sanitizeOps: false,
sanitizeResources: false,
});
+
+// Test for: https://github.com/denoland/fresh/issues/1655
+Deno.test({
+ name: "don't duplicate css class",
+ async fn() {
+ await withFresh(
+ "./tests/fixture_twind_app/main.ts",
+ async (address) => {
+ const res = await fetch(`${address}/app_class`);
+ assertEquals(res.status, 200);
+
+ // Don't use an HTML parser here which would de-duplicate the
+ // class names automatically
+ const html = await res.text();
+ assertMatch(html, /html class="bg-slate-800">/);
+ assertMatch(html, /head class="bg-slate-800">/);
+ assertMatch(html, /body class="bg-slate-800">/);
+ },
+ );
+ },
+ sanitizeOps: false,
+ sanitizeResources: false,
+});
+// Test for: https://github.com/denoland/fresh/issues/1655
+Deno.test("don't duplicate css class with twindV1", async () => {
+ await withFresh(
+ {
+ name: "./tests/fixture_twind_app/main.ts",
+ options: {
+ env: {
+ TWIND_V1: "true",
+ },
+ },
+ },
+ async (address) => {
+ const res = await fetch(`${address}/app_class`);
+ assertEquals(res.status, 200);
+
+ // Don't use an HTML parser here which would de-duplicate the
+ // class names automatically
+ const html = await res.text();
+ assertMatch(html, /html class="bg-slate-800">/);
+ assertMatch(html, /head class="bg-slate-800">/);
+ assertMatch(html, /body class="bg-slate-800">/);
+ },
+ );
+});