## 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
- 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>
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>
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
When `rollupOptions.output.entryFileNames` is customized in vite config
(e.g. `[hash].mjs`), the generated `server.js` was hardcoding
`server-entry.mjs` as the import path, causing the server to fail to
start.
This fix reads the actual entry filename from the Vite manifest and uses
it in the generated `server.js` import, falling back to
`server-entry.mjs` when no custom naming is configured.
---------
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mappings were wrong for a few reasons:
- Missing source map generation in one babel transform
- setting `compact: false` causes vite to generate incorrect mappings in
`vite:import-analysis`
- stack traces need to be mapped by vite
Fixes https://github.com/denoland/fresh/issues/3609
The Vite plugin was not filtering out test files from route discovery,
causing test files in routes/ (e.g., routes/api/counter_test.ts) to be
bundled into production builds, inflating bundle sizes by ~20KB per test
file and including unnecessary test dependencies.
Root cause: Vite plugin defaulted ignore patterns to [] while Builder
correctly defaults to [TEST_FILE_PATTERN].
This fix:
- Defines TEST_FILE_PATTERN in shared constants.ts for reusability
- Exports TEST_FILE_PATTERN from internals_dev.ts for Vite plugin access
- Updates Vite plugin default from [] to [TEST_FILE_PATTERN]
- Updates Builder to import TEST_FILE_PATTERN from constants.ts
- Ensures test files matching /[._]test\.(?:[tj]sx?|[mc][tj]s)$/ are
excluded
- Adds integration test to prevent regression
- Allows Deno best practice of colocating test files without bundling
them
Test coverage (prevents regression):
- Unit test: walkDir respects skip patterns
- Unit test: crawlRouteDir excludes test files
- Integration test: Vite builds exclude test files from output
Fixes#3558
fix#3521
Generated PR message below
---
## Problem
Island files named after JavaScript global objects (e.g., Map.tsx,
`Set.tsx`, `Array.tsx`, `Promise.tsx`) cause runtime errors. The
generated boot code uses object shorthand syntax that resolves to the
global constructor instead of the imported component:
```javascript
import Map from "/islands/Map.tsx";
boot({Map}, props); // {Map} resolves to global Map constructor
```
This results in `TypeError: Map is not a constructor` when the runtime
attempts to instantiate islands.
## Solution
Generate safe prefixed variable names (`__FRSH_ISLAND_N`) for island
imports and use explicit object property syntax to preserve the original
island names:
```javascript
import __FRSH_ISLAND_0 from "/islands/Map.tsx";
boot({"Map":__FRSH_ISLAND_0}, props);
```
This approach:
- Eliminates variable shadowing in all contexts (no scope collisions)
- Preserves original island names in HTML markers, error messages, and
runtime registry
- Allows any valid filename without restrictions
- Follows existing Fresh conventions for generated identifiers
## Changes
- preact_hooks.ts: Updated client-side boot script generation
- dev_build_cache.ts: Updated server-side snapshot generation
- Added integration tests for both Builder and Vite build systems
- Added documentation comment explaining why globals aren't in
`JS_RESERVED`
## Testing
Both tests verify that islands named after globals build successfully
and use safe variable names in generated code. Tests confirm the bug is
detected when fixes are reverted.
This PR makes nested islands work. Problem was that only entry files
have the `src` property in the vite manifest. For that we need to ensure
that every island is an entry point.
Fixes https://github.com/denoland/fresh/issues/3439
closes#3391
---
Generated PR message:
Fix base path handling for assets in plugin-vite
Fixes issue where Fresh apps mounted at non-root paths (e.g., /ui) in
frameworks like Hono would fail to load assets correctly.
Problem
When mounting a Fresh app with app.mount('/ui', UI.fetch), the HTML
would load but all assets (CSS, JS, images) would return 404 because
asset paths
were hardcoded to start with /assets/ instead of respecting the Vite
base configuration.
Solution
- Modified packages/plugin-vite/src/plugins/server_entry.ts to read
Vite's base config and apply it to asset paths
- Added getAssetPath() helper function to construct proper asset URLs
with base path
- Updated both CSS and asset file registration to use the base path
Testing
Added comprehensive test case "vite build - base path asset handling"
that:
- Builds demo with custom base path /my-app/
- Verifies generated server.js contains correctly prefixed asset paths
- Follows existing test patterns and utilities
Usage
Users can now properly mount Fresh apps by configuring both:
```ts
// vite.config.ts
export default defineConfig({
base: "/ui/",
plugins: [fresh()],
});
// main.ts
const app = new App({ basePath: "/ui" });
// hono-app.ts
app.mount('/ui', UI.fetch); // Assets now work correctly
```
Backward compatible - no changes needed for apps mounted at root path.
Fix#3232
Disclaimer: This code was mostly generated by GitHub Copilot agent using
Sonnet-4, but tested and verified by me.
---------
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
We're having a growing number of packages in this repository. This PR
moves them into a `packages/` directory like it's commonly done in other
projects.