263 Commits
Author SHA1 Message Date
paula 6e37c2aea7 Bump version 2026-11-12 14:58:28 -03:00
paula 7595cf396f Don't redirect to https if the request didn't come from https 2026-11-12 14:57:38 -03:00
paula 0b6be21d14 Bump version 2026-11-11 17:17:12 -03:00
paula 8c552d05d1 f-update-url 2026-11-11 17:16:21 -03:00
paula 3866b47741 Button partials with any methods 2026-11-11 16:56:47 -03:00
paula 8400c019e0 Make partials support any http method :3 2026-11-11 16:27:12 -03:00
paula 0e6aa1d232 go back to preact 10 lol 2026-11-11 15:23:56 -03:00
paula dd635e0fbe bump init 2026-11-11 14:54:02 -03:00
paula dda4a30f9c Bump version 2026-11-11 14:50:49 -03:00
paula 8aa05e104d Fix warning with vite dev 2026-11-11 14:46:51 -03:00
paula 216d54a0ae Start renaming 2026-11-11 11:45:20 -03:00
Luca Casonato 86d6cdeb33 www: change domain to usefresh.dev (#3831) 2026-06-03 16:35:21 +02:00
Leo Kettmeir 56faed1998 fix: stylesheet links in <Head> drop entry CSS (#3825)
The Head cache key for <link> excluded href for every rel, so any <link
rel="stylesheet"> in <Head> collided with entry-asset stylesheets (e.g.
Tailwind) and replaced them at the layout's <head> position. The href
exclusion was added to let <Head> override a singleton like canonical
without a key; scope it to those rels so distinct stylesheets no longer
dedupe.

Closes #3824
2026-05-27 15:10:31 +02:00
Hajime-san 3afaaf4f78 fix: CSS modules not working in _app/_layout/_error and across routes in non-island components (#3781) 2026-05-27 08:32:41 +02:00
072d09297e fix: inject client entry on islands-free pages for HMR (#3810)
Fixes denoland/fresh#3806

---------

Co-authored-by: fibibot <fibibot@users.noreply.github.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2026-05-27 08:15:51 +02:00
Bartek Iwańczuk 1fcf2d9ad5 fix: support WebSocket upgrades in dev server (#3823)
Vite's Connect-based dev server dispatches WebSocket upgrades as
'upgrade' events on the underlying http.Server rather than routing them
through middleware, so `Deno.upgradeWebSocket()` was never reached and
the client hung in CONNECTING. The plugin now attaches an upgrade
listener that hands the raw node socket off to Fresh's existing
`ctx.upgrade()` path.

The plumbing leans on denoland/deno#33342, which taught
`Deno.upgradeWebSocket` to accept a `{ socket, head }` option for
requests that didn't come in through `Deno.serve`. A
`WeakMap<Request, { socket, head }>` kept on `globalThis` acts as the
side channel: the plugin's upgrade listener populates it,
`ctx.upgrade()` reads and clears it before calling Deno. The map lives
on `globalThis` because Vite's SSR runner evaluates `context.ts`
separately from Deno's own load of the plugin, so each side would
otherwise hold its own module-local instance.

Fixes #3350
2026-05-27 07:51:19 +02:00
d738f22e02 fix: handle non-standard HTTP methods in router (#3808)
Fixes #3804.

Co-authored-by: lunadogbot <lunadogbot@users.noreply.github.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2026-05-26 14:23:46 +00:00
Bartek Iwańczuk 724879d1aa fix: type reconnectTimer as setTimeout return value (#3820)
The dev HMR client declares `reconnectTimer` as `number`, but the
runtime type of `setTimeout`'s return value is a `Timeout` object, so `deno
check` now fails with `TS2322: Type 'Timeout' is not assignable to type
'number'` at `packages/fresh/src/runtime/client/dev_hmr.ts:32`. This is blocking
every PR's type check job. Switching the annotation to
`ReturnType<typeof setTimeout>` keeps the declaration accurate without
committing to a specific runtime's timer type.
2026-05-26 15:13:16 +02:00
Bartek Iwańczuk 39b5f06f8a chore: release 2.3.3 (#3799)
## Summary

- Bump `@fresh/core` 2.3.2 → 2.3.3
- Bump `@fresh/plugin-vite` 1.1.1 → 1.1.2
- Bump `@fresh/init` 2.3.2 → 2.3.3
- Bump `@fresh/update` 2.3.2 → 2.3.3

Reverts the broken CJS shim (#3798) and releases the restored Babel CJS
transform.
2026-04-28 13:28:20 +02:00
Bartek Iwańczuk 8c148663e6 revert: bring back Babel CJS transform (#3798)
## Summary

Reverts two commits that broke CJS package handling in dev mode:

- Reverts #3793 (CJS detection regex fix)
- Reverts #3767 (removal of Babel CJS→ESM transform)

The simplified CJS shim introduced in #3767 has two fundamental issues:
1. **Detection**: the heuristic (`code.includes("export ")`) is fooled
by comments containing "export"
2. **Named exports**: the shim only provides `export default
module.exports`, so `import { trace } from "@opentelemetry/api"` returns
`undefined` (#3797)

The Babel-based transform handled both correctly. Bringing it back until
we can replace it with a proper solution using `deno_ast`'s CJS parser.
2026-04-28 13:20:33 +02:00
Bartek Iwańczuk 4ba300b02d chore: release 2.3.2 (#3796)
## Summary

- Bump `@fresh/core` 2.3.1 → 2.3.2
- Bump `@fresh/plugin-vite` 1.1.0 → 1.1.1
- Bump `@fresh/init` 2.3.1 → 2.3.2
- Bump `@fresh/update` 2.3.1 → 2.3.2

Patch release for the CJS detection regression fix (#3793).
2026-04-28 09:15:54 +02:00
Bartek Iwańczuk 838f41abc5 fix: CJS detection regression for packages with "export" in comments (#3793)
Closes https://github.com/denoland/fresh/issues/3794

Fixes a regression from #3767 where CJS npm packages fail with `exports
is not defined` in dev mode.

- The old heuristic (`code.includes("export ")`) was fooled by the word
"export" appearing in comments of CJS files — e.g. `@opentelemetry/api`
has `// TODO: Remove ProxyTracerProvider export in the next major
version.` which caused the CJS shim to be skipped entirely
- Replaces the naive string check with two-layer detection:
1. **Package.json `type` field** (Node.js semantics): `.cjs` → always
CJS, `.js` → CJS unless nearest `package.json` has `"type": "module"`.
Results cached per directory.
2. **ESM statement regex fallback**: for dual CJS/ESM packages that ship
ESM in `.js` without `"type": "module"` (e.g. `@opentelemetry/api`,
`preact-render-to-string`), detects actual ESM syntax including minified
forms like `import{` and `export*from`
- Adds a test importing from a real CJS npm package (`qs`) in
`node_modules` — the existing "CJS test" fixtures were local ESM files
that never exercised the shim path
2026-04-28 09:02:44 +02:00
Bartek Iwańczuk 71e849cfcf chore: release 2.3.1 (#3792)
- Bump `@fresh/core` to `2.3.1`
- Bump `@fresh/init` to `2.3.1`
- Bump `@fresh/update` to `2.3.1`
- Bump `@fresh/plugin-vite` from `1.0.8` to `1.1.0`
- Bump `@fresh/plugin-tailwind-v3` from `1.0.1` to `1.1.0`

The plugin packages were not published during the 2.3.0 release despite
having significant changes merged. Notable fixes in `@fresh/plugin-vite`
include immutable caching for Vite-built assets (#3761), CSS modules in
layouts (#3764), and multiple `staticDir` support (#3759).

Also updates `FRESH_VITE_PLUGIN` version constant in `@fresh/init` so
new projects scaffold with the correct plugin version.

Closes #3784
2026-04-27 17:55:14 +02:00
Bartek Iwańczuk 1955b10003 chore: release @fresh/plugin-vite@1.1.0 and @fresh/plugin-tailwind-v3@1.1.0 (#3789)
Closes #3784
2026-04-27 16:46:38 +02:00
LachandBartek Iwańczuk c06a84e1e0 fix: keep ?fresh-partial an implementation detail (#3776)
When encountering redirect during route change with partials enabled,
url in address bar (history api) is being left as ?fresh-partial=true,
this doesn't seem right

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2026-04-26 08:27:11 +00:00
Bartek Iwańczuk b9a314ba1d refactor: remove CJS and env var Babel transforms, let Vite handle natively (#3767)
## Summary

- **Replace Babel env var transforms with Vite's native `define`** —
`process.env.FRESH_PUBLIC_*` and `import.meta.env.FRESH_PUBLIC_*` now
use Vite's built-in `define` config. `Deno.env.get()` calls use a
lightweight regex-based transform (~10 lines vs 78-line Babel plugin).

- **Remove the 960-line CJS→ESM Babel transform** — Instead of
transforming CJS to ESM via Babel, let Vite handle CJS packages
natively:
- **Build mode**: Rollup's `@rollup/plugin-commonjs` handles CJS (always
has, but was bypassed by `deno.ts` loading through `@deno/loader`)
- **Dev mode**: A ~30-line CJS shim wraps `node_modules` CJS files with
`module`/`exports`/`require` so Vite's SSR module runner can evaluate
them
- `deno.ts` no longer attaches `meta.deno` to file:// resolved paths —
Vite loads them from disk directly

- **Remove `noDiscovery: true`** — Vite's dependency optimizer can now
pre-bundle CJS packages for the client

- **Fix React compat aliasing** — Apply `resolve.alias` (react →
preact/compat) in `deno.ts` before `@deno/loader` resolution, so the
alias works even when packages are non-external in SSR

Net: **~2,050 lines deleted**, ~150 lines added.

Fixes #3619, fixes #3653, fixes #3505, fixes #3478, fixes #3449.
2026-04-25 14:40:11 +02:00
Bartek Iwańczuk d16172e420 chore: release 2.3.0 (#3749) 2026-04-24 17:15:32 +02:00
Bartek Iwańczuk 0ab5a2ab28 feat: add first-class WebSocket support via ctx.upgrade() and app.ws() (#3774)
## Summary

- **`ctx.upgrade()`** on the `Context` class with two overloads:
- **Bare mode**: `ctx.upgrade()` or `ctx.upgrade(options)` returns `{
socket, response }` for manual event wiring
- **Managed mode**: `ctx.upgrade(handlers)` accepts `{ open, message,
close, error }` and returns the upgrade `Response` directly
- **`app.ws(path, handlers, options?)`** shorthand that registers a GET
route with automatic WebSocket upgrade (managed mode only)
- Both support `idleTimeout` and `protocol` options forwarded to
`Deno.upgradeWebSocket()`
- Throws `HttpError(400)` on non-WebSocket requests
- Case-insensitive `Upgrade` header check per RFC 6455 §4.2.1
- Exports `WebSocketHandlers` and `WebSocketUpgradeOptions` types from
`fresh`
- Full documentation page with examples for managed mode, bare mode,
broadcast chat, and client-side usage
2026-04-22 19:17:43 +02:00
SébastienandBartek Iwańczuk 49c4be1ac6 fix: handle commas in static file paths (#3770)
After #3659, static file handling correctly supports spaces and encoded
paths, but filenames containing commas are not resolved.

Example:
- File: `foo,bar.css`
- Stored in cache as: `/foo%2Cbar.css`
- Request: `/foo,bar.css`

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
2026-04-22 08:24:48 +00:00
ecc42850b9 fix: in sortRoutePaths: sort files alphabetically (#3769)
Closes #3773

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-21 17:20:47 +00:00
Bartek IwańczukandClaude Opus 4.6 36dd6375eb fix: CSS modules not working in _app/_layout/_error and across routes in dev (#3764)
Islands used in `_app.tsx`, `_layout.tsx`, or `_error.tsx` are
discovered after `<head>` has already rendered, so their CSS `<link>`
tags were never injected. `FreshScripts` (at end of `<body>`) now emits
late CSS for any islands missed by `RemainingHead`, using an
`injectedCss` set to avoid duplicates.

In dev mode, `collectCss` only walked the `fresh:client-entry` module
graph, missing CSS imported by island modules. The dev server now also
walks `fresh-island::*` module graphs when collecting CSS.

Note: late-injected `<link>` tags in `<body>` may cause a brief flash of
unstyled content — this is inherent to the problem since `<head>`
renders before `<body>` islands are discovered.

Closes #3633

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 17:37:10 +02:00
Bartek IwańczukandClaude Opus 4.6 14f895517e fix: add cache-bust query param to Vite asset URLs for immutable caching (#3761)
## Summary
- Vite-built assets (JS chunks, CSS) were served with `Cache-Control:
no-cache, no-store` because the static files middleware only recognized
builder-path assets (under `/_fresh/js/{BUILD_ID}/`) as immutable
- Adds an `immutable` flag to `FileSnapshot`, `StaticFile`, and
`PendingStaticFile` interfaces
- The Vite plugin marks manifest chunks and CSS as `immutable: true`
(these have content-hashed filenames), while public directory files
remain non-immutable
- The static files middleware checks `file.immutable` alongside the
existing path and query param checks

Closes #3282

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 16:46:41 +02:00
Bartek IwańczukandClaude Opus 4.6 f39a198f8d fix: ignore temp files in Vite watcher to prevent dev server crash (#3763)
## Summary
- Adds default `server.watch.ignored` patterns to the Fresh Vite plugin
config
- Ignores `*.tmp.*`, `*.timestamp-*`, editor swap files (`*.swp`,
`*.swo`, `*~`, `.#*`)
- Prevents a `watchFs` race condition on Linux where Deno tries to open
a short-lived file that was already deleted, crashing the dev server
with `NotFound: No such file or directory`

Users can still override or extend these patterns in their own
`vite.config.ts` since Vite merges config from plugins.

Closes #3585

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 13:14:32 +02:00
Bartek IwańczukandClaude Opus 4.6 28cce5f607 feat: add _freshIndicator support for partial form submits (#3753)
## Summary
- Extends the `_freshIndicator` loading signal to form submissions, not
just anchor clicks
- Checks the submitter element first, falling back to the form element
- Wraps the fetch in try/finally to ensure the indicator resets on
success or failure
- Adds 3 browser tests: indicator on button, indicator on form, and
submitter-over-form precedence

Closes #3504

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 12:21:39 +02:00
Bartek IwańczukandClaude Opus 4.6 af3f30dbaa fix: warn instead of crash on invalid HTML nesting around islands (#3762)
## Summary
- When a block-level element (e.g. `<div>`) is placed inside an inline
element (e.g. `<p>`) that wraps an island, the browser fixes the invalid
nesting by splitting the parent, moving Fresh's comment markers into
different DOM nodes
- Previously this caused a fatal `DOMException` during hydration,
crashing all client-side JS on the page
- Now Fresh detects that `start.parentNode !== end.parentNode` before
calling `createRootFragment`, logs a descriptive error message
explaining the invalid nesting, and skips the broken island instead of
crashing

Example of the error message:
```
Fresh hydration error: the island "BugIsland" has invalid HTML nesting.
Its start and end markers were reparented by the browser into different
DOM nodes. This is usually caused by placing a block-level element
(like <div>) inside an inline element (like <p> or <span>). Check the
HTML around this island for invalid nesting.
```

Closes #2121

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 12:20:31 +02:00
Bartek IwańczukandClaude Opus 4.6 07878fcce9 feat: add trustProxy option to respect X-Forwarded-* headers (#3757)
## Summary
- Adds `trustProxy` option to `FreshConfig` (default: `false`)
- When enabled, the handler reads `X-Forwarded-Proto` and
`X-Forwarded-Host` headers and rewrites `ctx.url` so it reflects the
actual client-facing URL
- Useful for apps running behind nginx, Caddy, or other reverse proxies
where `ctx.url` would otherwise return `http://` instead of `https://`

Closes #2660

## Usage
```ts
const app = new App({ trustProxy: true });
```

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 07:53:24 +00:00
Bartek IwańczukandClaude Opus 4.6 990aeb03f3 feat: support multiple staticDir entries (#3759)
## Summary
- `staticDir` now accepts `string | string[]` in both the **Vite
plugin** (`FreshViteConfig`) and the **Builder API** (`BuildOptions`)
- When multiple directories are specified, they are searched in order
and the first match wins
- **Vite plugin**: first dir maps to Vite's native `publicDir`; extra
dirs are served manually in the dev server and walked during production
builds
- **Builder API**: both `MemoryBuildCache` (dev) and `DiskBuildCache`
(prod) iterate over all directories
- Updated tailwind v3 plugin to use `config.root` instead of
`path.dirname(config.staticDir)`
- Docs updated: `static-files.md`, `vite.md`, `builder.md`

Closes #3105

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 07:49:32 +00:00
Bartek IwańczukandClaude Opus 4.6 c0a866d027 fix: improve update tool output for Fresh 2 projects (#3754)
## Summary
- Detects whether a project is already on Fresh 2 by checking
`deno.json` imports
- Shows "Updating Fresh to X.Y.Z..." instead of "Starting Fresh 1 to
Fresh 2 migration..." for existing Fresh 2 projects
- Only shows "Breaking changes may require additional manual updates"
warning for actual Fresh 1→2 migrations
- Summary/completion messages adapt accordingly ("Update" vs
"Migration")

Closes #3688

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 09:48:38 +02:00
Bartek IwańczukandClaude Opus 4.6 fc0ff66b80 fix: active links consider query params and respect existing aria-current (#3755)
## Summary
- `matchesUrl()` now considers query parameters — links with query
params that don't match the current URL get `Ancestor` instead of
`Current` status
- Links with a user-set `aria-current` attribute are left untouched
(both server and client side), fixing daisyUI tab components and similar
use cases
- Client-side `updateLinks()` passes search params and respects user-set
attributes

Closes #3474

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 09:42:02 +02:00
Bartek IwańczukandClaude Opus 4.6 d6b0a169a3 fix: improve CJS-to-ESM transform for better npm compatibility (#3697)
## Summary

Fixes several issues in the Fresh Vite plugin's CommonJS-to-ESM Babel
transform (`commonjs.ts`) that caused npm packages to break during
builds while working fine in dev mode.

- **Fix `.mts`/`.cts` extension detection** — `.cts` was incorrectly in
the ESM branch (should be `.mts`), causing TypeScript CJS files to skip
the transform
- **Handle `require.resolve()`** — injects
`createRequire(import.meta.url)` polyfill so `require.resolve()` calls
work in ESM output (#3619)
- **Polyfill `__dirname`/`__filename`** — injects
`fileURLToPath`/`dirname` based polyfill when these CJS globals are used
- **Use `var` instead of `let` for `_default`** — avoids TDZ errors when
Rollup reorders declarations in bundled output (#3653)
- **Track `module.exports.X` as named exports** — the MemberExpression
visitor now handles both `exports.X` and `module.exports.X` patterns

Addresses: #3619, #3653

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 16:29:48 +02:00
Bartek IwańczukandClaude Opus 4.6 9875146cc4 fix: improve Deno module resolution in Vite plugin (#3734)
## Summary

Three targeted fixes to Fresh's Vite plugin for better module
resolution, plus new test coverage.

### 1. Workspace import map resolution
Pass the importer's file URL to `loader.resolve()` so bare specifiers
from workspace member packages resolve through the correct import map —
not just the root `deno.json`.

Fixes #3654

### 2. Remote island resolution
Use `this.resolve(spec)` in the `fresh-island::` and
`fresh-client-island::` resolveId handlers (`server_snapshot.ts` /
`client_snapshot.ts`) so JSR remote islands get proper `\0deno::`
specifiers. Without this, remote islands resolved to bare specifiers
that Vite couldn't load.

Fixes #3437

### 3. Babel JSX operator precedence fix
`!ssr && id.endsWith(".tsx") || id.endsWith(".jsx")` → `!ssr &&
(id.endsWith(".tsx") || id.endsWith(".jsx"))`. The missing parentheses
caused `.jsx` files to incorrectly get Preact JSX transforms during SSR.

### Other changes
- Bump `@deno/loader` from ^0.3.10 to ^0.4.0 (needed for workspace
resolution fix)
- Bump `@astral/astral` from ^0.5.5 to ^0.5.6 (fixes `@std/async@1.2.0`
compat)
- Add dev server tests for CJS module import and maxmind CJS (#3653)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 15:40:46 +02:00
Bartek IwańczukandClaude Opus 4.6 3a51f82da6 fix: use deno run for init instead of deno create before 2.3.0 (#3746)
## Summary
- Reverts all references from `deno create @fresh/init` back to `deno
run -Ar jsr:@fresh/init` across docs, READMEs, homepage, and CLI help
text
- Removes the deprecation warning in `packages/init/src/mod.ts` that
told users to switch to `deno create`

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:19:14 +02:00
Bartek IwańczukandClaude Opus 4.6 a872a70e5f refactor: add integrationTest() helper to reduce test boilerplate (#3711)
## Summary
- Adds an `integrationTest()` wrapper in
`packages/fresh/src/test_utils.ts` that calls `Deno.test` with
`sanitizeOps: false` and `sanitizeResources: false`
- Converts ~88 integration tests across 5 files to use the new helper,
removing repetitive sanitizer boilerplate
- Net reduction of ~344 lines (-1678/+1334)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 19:14:10 +02:00
Bartek IwańczukandClaude Opus 4.6 d6fc1d08a8 fix: normalize Windows paths in generated snapshot and server entry (#3727)
## Summary
- When building on Windows, `path.relative()` produces backslash
separators (`\`) that get hardcoded into the generated `snapshot.js` and
`server.js` files
- If the bundle is then deployed to a Linux server (e.g. Windows CI →
Linux prod), those paths break at runtime
- Fix: add a `toPosix()` helper that normalizes all paths written into
generated files to use forward slashes, applied in three places:
  - `root` path passed to `generateServerEntry()`
  - `filePath` in `prepareStaticFile()` (from `path.relative()`)
- All path options inside `generateServerEntry()` (root, serverEntry,
snapshotSpecifier)

Closes #3513

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 15:12:47 +02:00
6dd2c97fb2 feat:Actually ship no JS by default (#3696)
In many places, Fresh marketing claims the framework ships no JS by
default, **this was false**.

This PR reworks core parts of the framework to check whether JS is
needed on the client with these criteria:
1. Use of islands
2. Use of Partials (`f-client-nav`)

If either of those those criteria are met, JavaScript will be loaded as
normal, but if both are false, then the `client-entry` script is omitted
from the page.

Fixes https://github.com/denoland/fresh/issues/3662

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:15:35 +00:00
8b0d42b82a fix: register files generated by Vite plugins in static file cache (#3534)
Fixes #3487 

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:04:46 +00:00
Bartek IwańczukandClaude Opus 4.6 400e217c5e feat: add View Transitions API support for client-side navigation (#3708)
## Summary

- Integrates the [View Transitions
API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transition_API)
into Fresh's existing partials system
- Opt-in via `f-view-transition` attribute, progressive enhancement
(falls back gracefully)
- Wraps all navigation types (link clicks, popstate, form submissions)
in `document.startViewTransition()`

## Usage

```html
<body f-client-nav f-view-transition>
  <!-- your app -->
</body>
```

Customize animations with standard CSS:
```css
::view-transition-old(root) {
  animation: fade-out 0.2s ease-in;
}
::view-transition-new(root) {
  animation: fade-in 0.2s ease-out;
}
```

Per-element transitions work via `view-transition-name`:
```css
.sidebar { view-transition-name: sidebar; }
```

## Design decisions

- **Opt-in** — only activates when `f-view-transition` attribute is
present, can be disabled with `f-view-transition="false"`
- **Progressive** — falls back to regular partial updates when the
browser doesn't support the View Transitions API
- **Minimal** — 35 lines of implementation, integrates into existing
partials infrastructure rather than building a parallel navigation
system

Closes https://github.com/denoland/fresh/issues/3458

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 19:56:37 +00:00
Bartek IwańczukandClaude Opus 4.6 cf73d29c3a fix: CSP user directives now override defaults instead of duplicating (#3724)
Fixes #3552

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 19:53:14 +00:00
4edfe2f5a4 perf: pre-compile middleware chains at build time (#3104)
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>
2026-03-29 21:50:22 +02:00
Bartek IwańczukandClaude Opus 4.6 dc2324807c feat: add nonce support for inline style and script tags in CSP (#3709)
## 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>
2026-03-29 21:45:13 +02:00