summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/two-pants-enjoy.md5
-rw-r--r--packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx3
-rw-r--r--packages/astro/e2e/fixtures/client-only/tsconfig.json5
-rw-r--r--packages/astro/src/vite-plugin-astro/compile.ts6
-rw-r--r--packages/astro/src/vite-plugin-jsx/index.ts6
5 files changed, 25 insertions, 0 deletions
diff --git a/.changeset/two-pants-enjoy.md b/.changeset/two-pants-enjoy.md
new file mode 100644
index 000000000..b6a54983e
--- /dev/null
+++ b/.changeset/two-pants-enjoy.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fix `client:only` imports with `"importsNotUsedAsValues": "error"` tsconfig
diff --git a/packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx b/packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx
index 30d804199..770f93890 100644
--- a/packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx
+++ b/packages/astro/e2e/fixtures/client-only/src/components/ReactCounter.jsx
@@ -1,5 +1,8 @@
import { useState } from 'react';
+// accessing browser globals as side effects is allowed if the component is client:only
+console.log(document.title)
+
/** a counter written in React */
export function Counter({ children, id }) {
const [count, setCount] = useState(0);
diff --git a/packages/astro/e2e/fixtures/client-only/tsconfig.json b/packages/astro/e2e/fixtures/client-only/tsconfig.json
new file mode 100644
index 000000000..9e4ac6056
--- /dev/null
+++ b/packages/astro/e2e/fixtures/client-only/tsconfig.json
@@ -0,0 +1,5 @@
+{
+ "compilerOptions": {
+ "importsNotUsedAsValues": "error"
+ }
+} \ No newline at end of file
diff --git a/packages/astro/src/vite-plugin-astro/compile.ts b/packages/astro/src/vite-plugin-astro/compile.ts
index f9e581e84..e63c0605c 100644
--- a/packages/astro/src/vite-plugin-astro/compile.ts
+++ b/packages/astro/src/vite-plugin-astro/compile.ts
@@ -41,6 +41,12 @@ export async function cachedFullCompilation({
loader: 'ts',
target: 'esnext',
sourcemap: 'external',
+ tsconfigRaw: {
+ compilerOptions: {
+ // Ensure client:only imports are treeshaken
+ importsNotUsedAsValues: 'remove',
+ },
+ },
});
} catch (err: any) {
await enhanceCompileError({
diff --git a/packages/astro/src/vite-plugin-jsx/index.ts b/packages/astro/src/vite-plugin-jsx/index.ts
index b4d90c79d..534c8a853 100644
--- a/packages/astro/src/vite-plugin-jsx/index.ts
+++ b/packages/astro/src/vite-plugin-jsx/index.ts
@@ -140,6 +140,12 @@ export default function jsx({ settings, logging }: AstroPluginJSXOptions): Plugi
loader: getEsbuildLoader(id),
jsx: 'preserve',
sourcemap: 'inline',
+ tsconfigRaw: {
+ compilerOptions: {
+ // Ensure client:only imports are treeshaken
+ importsNotUsedAsValues: 'remove',
+ },
+ },
});
return transformJSX({
code: jsxCode,