From 2ccc81d3e48877df48bccaa5e2f6eb3333b7575b Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Mon, 23 Mar 2026 17:01:35 +0300 Subject: [PATCH] Fix path error in Footer component leading to 500 error on server --- eslint.config.ts | 30 +++++++++++++++++++ src/components/Footer/index.astro | 3 +- src/components/scripts/utils/siteUrlClient.ts | 19 +++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 6b3dd8f17..f99a89024 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -837,6 +837,32 @@ export default [ ], }, }, + { + files: [ + '**/*.astro', + '**/*.ts', + '**/*.tsx', + ], + ignores: [ + 'src/**/client/**', + 'src/components/scripts/**/*', + 'src/pages/testing/**/*', + 'src/components/scripts/utils/__tests__/siteUrlClient.spec.ts', + ], + rules: { + 'no-restricted-imports': [ + level, + { + paths: [ + { + name: '@components/scripts/utils/siteUrlClient', + message: 'Only browser-executed client code may import @components/scripts/utils/siteUrlClient. SSR, Astro frontmatter, actions, API routes, and other server-side code must resolve site URLs from runtime-safe server helpers or request context instead.', + }, + ], + }, + ], + }, + }, { files: [ '**/*.astro', @@ -849,6 +875,10 @@ export default [ level, { paths: [ + { + name: '@components/scripts/utils/siteUrlClient', + message: 'Astro files must not import @components/scripts/utils/siteUrlClient. Browser-only site URL helpers are unsafe in Astro frontmatter because those files can execute during SSR. Resolve site URLs from Astro context or use a runtime-safe server helper instead.', + }, { name: '@lib/config/siteUrlServer', message: 'Astro files must not import @lib/config/siteUrlServer. Resolve site URLs from Astro context or use a runtime-safe helper instead.', diff --git a/src/components/Footer/index.astro b/src/components/Footer/index.astro index 5d1607417..66d8b8b88 100644 --- a/src/components/Footer/index.astro +++ b/src/components/Footer/index.astro @@ -1,6 +1,5 @@ --- import contactData from '@content/contact.json' -import { getSiteUrl } from '@components/scripts/utils/siteUrlClient' import { formatPhoneNumber } from '@components/Footer/server' import Avatar from '@components/Avatar/index.astro' import BugReporter from '@components/BugReporter/index.astro' @@ -227,7 +226,7 @@ const iconButtonClasses = [
{/* Page footer RSS link */} diff --git a/src/components/scripts/utils/siteUrlClient.ts b/src/components/scripts/utils/siteUrlClient.ts index 30d433208..40c4236ce 100644 --- a/src/components/scripts/utils/siteUrlClient.ts +++ b/src/components/scripts/utils/siteUrlClient.ts @@ -1,10 +1,27 @@ /** - * Client-side method to determine correct URL + * Browser-only site URL helper. + * + * Safe to use: + * - in client bundle code under src/components/scripts or component/page client directories + * - in browser-executed test fixtures that intentionally verify client behavior + * + * Not safe to use: + * - in Astro frontmatter + * - in server-rendered .astro components + * - in actions, API routes, email generation, or any other SSR/server code + * + * Why: + * - this module imports astro:env/client, which is meant for browser/client code + * - it returns a browser-oriented static site URL, not a request-aware runtime URL + * - server-side code must instead use Astro context, request origin, or server-safe URL helpers */ import { DEV_SERVER_PORT } from 'astro:env/client' import { isProd, isE2eTest } from '@components/scripts/utils/environmentClient' +/** + * Returns the browser-facing site origin for client-side code. + */ export const getSiteUrl = () => { if (isProd() && !isE2eTest()) { return `https://www.webstackbuilders.com`