Skip to content
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/astro-env-treated-as-server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes `HTMLElement is not defined` error during HMR when using components with client-side scripts (e.g. Starlight `<Tabs>`) and the Cloudflare adapter
3 changes: 2 additions & 1 deletion packages/astro/src/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ASTRO_VITE_ENVIRONMENT_NAMES } from './core/constants.js';
export function isAstroServerEnvironment(environment: Environment) {
return (
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr ||
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender ||
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.astro
);
}

Expand Down
39 changes: 39 additions & 0 deletions packages/astro/test/units/environments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import type { Environment } from 'vite';
import { isAstroClientEnvironment, isAstroServerEnvironment } from '../../dist/environments.js';

/** Create a minimal mock Environment with only the `name` property. */
function env(name: string) {
return { name } as unknown as Environment;
}

describe('isAstroServerEnvironment', () => {
it('should return true for the ssr environment', () => {
assert.equal(isAstroServerEnvironment(env('ssr')), true);
});

it('should return true for the prerender environment', () => {
assert.equal(isAstroServerEnvironment(env('prerender')), true);
});

it('should return true for the astro environment', () => {
assert.equal(isAstroServerEnvironment(env('astro')), true);
});

it('should return false for the client environment', () => {
assert.equal(isAstroServerEnvironment(env('client')), false);
});
});

describe('isAstroClientEnvironment', () => {
it('should return true for the client environment', () => {
assert.equal(isAstroClientEnvironment(env('client')), true);
});

it('should return false for server environments', () => {
assert.equal(isAstroClientEnvironment(env('ssr')), false);
assert.equal(isAstroClientEnvironment(env('prerender')), false);
assert.equal(isAstroClientEnvironment(env('astro')), false);
});
});
Loading