Pre-compiles middleware chains once at startup instead of constructing
them per-request.
## Changes
- Replace `runMiddlewares(middlewares, ctx, onError)` (per-request) with
`compileMiddlewares(middlewares, onError)` (once at startup) which
returns a single `Middleware<State>` function
- Router now stores a single compiled handler per method/route (`T |
null`) instead of arrays (`T[]`)
- The compiled chain passes `tail` (the original `ctx.next`) as a
parameter to each step, avoiding the infinite recursion bug where a
compiled tail reads an already-overwritten `ctx.next` — safe under
concurrent requests
- Lazy middleware resolution is preserved: a lazy middleware is resolved
on first request and the resolved function replaces the lazy wrapper in
the closure
## Benchmarks
Synthetic benchmarks (10 middlewares, `deno bench`) show the per-request
savings are small in isolation — middleware execution and async/await
overhead dominate. The main value is architectural: building the chain
once is correct and eliminates per-request allocations, which may
compound under high concurrency.
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Auto-inject `nonce` attribute onto inline `<script>` and `<style>`
tags during server rendering
- Add `useNonce` option to the CSP middleware that replaces
`'unsafe-inline'` with per-request `'nonce-{value}'` directives
- Expose render nonce via `X-Fresh-Nonce` response header (internal,
stripped by CSP middleware)
## Usage
```ts
app.use(csp({ useNonce: true }));
```
This locks down the CSP policy so only Fresh-rendered inline
scripts/styles are allowed. Each request gets a unique nonce.
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Fixed an issue where basePath was not correctly applied in dev mode
for the root index route
- The dev server now uses root path "/" while preserving the configured
basePath for the main app
## Summary
- Adds a `console.warn` during SSR when a `<Partial>` uses
`mode="append"` or `mode="prepend"` without a `key` prop
- Without a key, Preact cannot correctly reconcile prepended/appended
children, leading to subtle rendering bugs
- No warning for `mode="replace"` (default) since keys aren't required
there
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Fixes#2610 — "Partial + redirect breaks islands"
- When a partial request (`?fresh-partial=true`) hits a server-side
redirect via `ctx.redirect()`, the `fresh-partial` search param is now
preserved in the redirect `Location` header
- Previously the param was lost, so the redirect target rendered as a
full page instead of a partial response, breaking island hydration
The fix is in `ctx.redirect()` in `packages/fresh/src/context.ts` — when
`this.isPartial` is true, the partial param is appended to the redirect
location (handling existing query params and hash fragments correctly).
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Add serialization/deserialization for all 8 Temporal types in the
jsonify module (used for island props): Instant, ZonedDateTime,
PlainDate, PlainTime, PlainDateTime, PlainYearMonth, PlainMonthDay,
Duration
- Stringify side guards with `typeof Temporal !== "undefined"` to avoid
ReferenceError when Temporal is unavailable
- Uses `.toString()` for serialization and `Type.from()` for
deserialization
Co-authored-by: Nano Miratus <nanomiratus@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Add a `./create` export to `@fresh/init` so users can scaffold
projects with `deno create @fresh/init` (Deno 2.7+)
- The old `deno run -Ar jsr:@fresh/init` continues to work but now shows
a deprecation warning
**New way (Deno 2.7+):**
```sh
deno create @fresh/init
```
**Old way (still works, with warning):**
```sh
deno run -Ar jsr:@fresh/init
```
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Inlined the `$ga4` module (from
`https://raw.githubusercontent.com/denoland/ga4/main/mod.ts`) into
`www/utils/ga4.ts`
- Replaced old `deno.land/std` URL imports with `@std/http`
(`getCookies`, `STATUS_TEXT`)
- Inlined the trivial `snakeCase` helper (was from `deno.land/x/case`)
- Removed `$ga4` import map entry from `deno.json`
The ga4 package was never published to jsr or npm, so inlining was the
cleanest way to eliminate the last raw URL-based dependency.
## Summary
- **docsearch**: Replaced `esm.sh` URL with `npm:@docsearch/js@^3.5.2`.
Added a type cast workaround in `SearchButton.tsx` since Deno's type
checker treats this npm package as CJS (missing `"type": "module"`).
- **imagescript**: Replaced `deno.land/x` URL with
`jsr:@matmen/imagescript@^1.3.0`. Clean swap, no code changes needed.
These were legacy URL-based imports from before Deno had native `npm:`
and `jsr:` support.
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Rewrite `tools/check_links.ts` to be more robust (inspired by
denoland/docs' `better_link_checker.ts`)
- Add `deno task check:links` to `deno.json`
- Wire it into CI as a new step (Ubuntu + v2.x only, after `build-www`)
- Add missing `docs/latest/examples/index.md` to fix broken
`/docs/examples` link
- Crawl up to 10 pages concurrently for faster link checking
## What the link checker does
1. Builds the www site with Vite
2. Launches a production server
3. Crawls all internal links starting from the root (10 pages
concurrently)
4. Reports broken links (4xx/5xx) with referrer info
5. Detects empty `href` attributes
6. Prints a summary at the end instead of throwing on first failure
Improvements over the old `check_links.ts`:
- Doesn't throw on first 404 — collects all failures and reports at the
end
- Detects empty hrefs
- Skips non-HTML content, fragment-only links, external links, and
common static file extensions
- Shows referrer for each broken link so you know where to fix it
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Adds a `pr-title` CI job that validates PR titles start with `feat:`,
`fix:`, `test:`, `chore:`, or `showcase:` and are all lowercase
- Updates `.github/CONTRIBUTING.md` with the title format rules and a
link to the full contributing docs
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- The CI `check:docs` task imports from
`raw.githubusercontent.com/denoland/std/.../_tools/check_docs.ts` which
intermittently fails with **429 Too Many Requests**, breaking CI on
unrelated PRs
- Vendor the script locally as `tools/check_docs_lib.ts` (from
`denoland/std`'s `_tools/check_docs.ts` + inlined `resolve` from
`_tools/utils.ts`) to eliminate the external dependency
- Both `@deno/doc` and `@std/collections` were already in the import
map, so no new dependencies
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Remove the Showcase page route, data, component, and all 175 showcase
images
- Remove "Showcase" from the navigation bar
- Keep the fresh-badge SVGs (still linked from external READMEs)
Also closed 12 open showcase PRs: #2691, #2861, #2846, #2720, #2282,
#2667, #2585, #1842, #2784, #1697, #2260, #2841.
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Handles the case when `Date.toISOString()` throws for invalid dates by
catching the error and serializing as `"Invalid Date"`
- Round-trips correctly: `new Date("Invalid Date")` serializes to
`["Date","Invalid Date"]` and deserializes back to an invalid `Date`
object
- Adds test case and snapshot for invalid `Date`
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
## Summary
- Update init command in `README.md` from `deno run -A -r
https://fresh.deno.dev` to `deno run -Ar jsr:@fresh/init` to match Fresh
2.x
- Fix `www/README.md` to use `deno task dev` (Vite dev server) instead
of `deno task start` (production server) for development workflow
---------
Co-authored-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This PR exposes the `HttpError` class for clients.
To do that I needed to make the error message optional to avoid bloating
up the bundle with lots of status strings.
Fixes https://github.com/denoland/fresh/issues/2995
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Adds a Contributing section to the Fresh documentation covering:
- Repository structure and package layout
- Getting started (clone, `deno task ok`)
- Development workflow (docs site, vite demo, `links` for external
projects)
- Testing (commands, conventions, known local issues)
Single page at `docs/latest/contributing/index.md`.
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix system crash (OOM) caused by updater spending time in folders like
docs/
- Skip hidden and vendor directories (node_modules, vendor, docs, etc.)
to avoid OOM
- free ASTs immediately
- ts-morph dependency bumped to ^27.0.2
Closes https://github.com/denoland/fresh/issues/3483
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix#3657
Static files with special characters in their names (spaces, `#`,
unicode, etc.) fail to load due to path encoding issues.
## Root cause
`prepareStaticFile()` uses `new URL(pathname, base)` to normalize paths,
but `new URL` doesn't properly encode characters that are already
percent-encoded in the filesystem path. For example, a file literally
named `test %20encodeUri` becomes `test%20%20encodeUri` (the space and
literal `%20` are indistinguishable), instead of the correct
`test%20%2520encodeUri`.
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## Summary
- Add `AGENTS.md` with guidelines for AI-assisted development on this
repo
- Documents git workflow (use `gh pr checkout`, run `deno fmt`, avoid
lockfile noise)
- Documents dev practices (`deno task ok`, stale remote specifier
hashes)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This adds a short clarification how imported assets vs. static files get
handled now with Vite to the existing documentation for static files.
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>