Files
Rosea/.agents/lessons/technical.md
T
mnovak a200832cfb [ui] LetterSlot: Add the page for A Letter from the Gardener, shown once the author writes it
docs/LETTER.md holds slots as comments only, so the player sees no change
until the author writes. The app bundles the letter at build time, a small
Markdown subset renders without {@html}, only https: and tel: become links,
and lint:copy now reads the letter. Review found turbo replaying a stale
build after the letter changed; docs/LETTER.md is now in its cache key.
2026-11-01 15:39:17 +01:00

58 lines
3.0 KiB
Markdown

# Technical
## A Vite config cannot import a workspace package's TypeScript source
**What happened.** `apps/rosea/vite.config.ts` imported the name constants from
`@rosea/schema`, whose `main` is `src/index.ts`. `vite build` failed with
`ERR_UNKNOWN_FILE_EXTENSION ".ts"`. `--configLoader runner` fixed the build. But
`svelte-check` loads the same config on its own, still failed, and printed
*failed to load config* while reporting 0 errors.
**Why it bit.** Vite bundles a config's relative imports but externalises anything
resolved through `node_modules`. Workspace packages are symlinks there, so Node
loads them natively, and Node 22.11 does not strip types. A tool that reads the config
for you has its own loader.
**How to apply it.** In a Vite config, import workspace code by **relative path**
to a dependency-free module. Treat a failure message inside a green run as a
failure: find which tool printed it.
## Vite escapes the quotes in an injected `<meta>` CSP
**What happened.** The built `index.html` carries `content="default-src &#39;self&#39;…"`.
A regex over the raw HTML looking for `'self'` would never match it.
**Why it bit.** The HTML is valid and the browser decodes the entities. Only a test
that reads the bytes sees the difference.
**How to apply it.** Read attributes from the DOM:
`page.locator('meta[http-equiv=…]').getAttribute('content')`. Keep raw-HTML checks for
byte-level questions, such as whether there is an inline `<script>` or where `<meta charset>` sits.
## Svelte 5 needs no preprocessor for `lang="ts"`
**What happened.** With `vitePreprocess()` in `svelte.config.js`, `svelte-check` tried
to load `vite.config.ts` to preprocess styles, and hit the error above. Removing the
preprocessor removed the problem, and every component still typechecks.
**Why it bit.** Svelte 5 strips type annotations natively. A preprocessor is only
needed for non-CSS style languages or TS features that emit code (enums, decorators).
**How to apply it.** Leave `svelte.config.js` as `export default {}` until a component
needs SCSS or emitted TS. Add the preprocessor in the same commit as that need.
## Turbo's cache does not see a file the app imports from outside its package
**What happened.** The app imports `docs/LETTER.md?raw`. With a sample letter written
into the file, `pnpm test:e2e` printed `@rosea/app:build: cache hit` and tested the
*old* bundle, so the link to the letter was missing. Turbo hashes a package's own
files, and `docs/` belongs to no package. Adding `docs/LETTER.md` to
`globalDependencies` in `turbo.json` turned it into a `cache miss`, and the test passed.
**Why it bit.** A build cache keyed on the wrong inputs gives a stale bundle that looks
fresh. This is CLAUDE.md §5.4 again, caused by the build tool and not the service worker.
**How to apply it.** Any file the app bundles from outside its package goes into
`globalDependencies` or the task's `inputs`, in the same commit as the import. To
check, change the file, run the build, and look for `cache miss`.