diff --git a/AGENTS.md b/AGENTS.md index bfd2e7dd..5ff9dedb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -431,6 +431,37 @@ When cleanup or reset must follow a specific lifecycle moment, use the matching Use `.server.ts` files for server-side code to isolate API keys. +### Chart Imports and SSR + +`layerchart` has internal circular dependencies that Vite cannot reliably evaluate during SSR. Never statically import `layerchart` or the `@cio/ui/base/chart` runtime barrel from a component that can enter the server module graph. + +- Import chart types from the dependency-free types module: `import type { ChartConfig } from '@cio/ui/base/chart/types'` (or the equivalent relative path inside `packages/ui`). +- Load chart runtime components with a browser-only dynamic import and render them inside an `{#await}` block guarded by `browser` or `typeof window !== 'undefined'`. +- In exercise submission renderers, reuse `submission-response-bar-chart.svelte` or `submission-response-pie-chart.svelte`; do not import the chart barrel directly. + +```svelte + + + + +{#if browser} + {#await loadChart() then Chart} + + + + {/await} +{/if} +``` + ### UI Components - Add new UI components under `packages/ui/src` following existing folder patterns. diff --git a/packages/ui/src/custom/exercise-question/renderers/thumbs/submission.svelte b/packages/ui/src/custom/exercise-question/renderers/thumbs/submission.svelte index 35736baf..96424c40 100644 --- a/packages/ui/src/custom/exercise-question/renderers/thumbs/submission.svelte +++ b/packages/ui/src/custom/exercise-question/renderers/thumbs/submission.svelte @@ -1,7 +1,8 @@ -{#if chartData.length > 0} - - - ({ label: d.label, color: d.color, value: d.responses }))} /> - -{:else} -

- {getSubmissionLabel(labels, 'submission.chart.no_data', 'No responses yet')} -

-{/if} +