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>
## 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>
## 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>
## 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>
## 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>
## 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>
## 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>
## 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>
## 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>
## Summary
- The inline HTML/CSS flow diagram in `docs/concepts/architecture` was
broken — marked's smartypants text transforms corrupted the `<style>`
block, stripping all styling
- Replaced with a standalone SVG
(`www/static/docs/architecture-flow-v2.svg`) using theme-neutral
mid-gray colors that are readable on both light and dark backgrounds
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
## 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>
## 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>
## 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>
## 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>
## 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>
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>
## 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>
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>