Commit Graph
113 Commits
Author SHA1 Message Date
Bartek IwańczukandClaude Opus 4.6 92e07f03b3 fix: resolve server entry filename from bundle chunks (#3719)
Closes #3655

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 20:45:32 +02:00
c863097779 fix: handle paths with whitespaces in staticFiles (#3659)
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>
2026-03-25 20:00:48 +01:00
421e3394a2 fix(vite): use manifest entry filename for server entry import (#3595)
## 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>
2026-03-25 18:47:02 +00:00
cdc14a0c6e Do not assign named exports into existing default export (#3494)
Fixes: https://github.com/denoland/fresh/issues/3492

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 19:40:46 +01:00
Eli ab14d1044c refactor(vite): replace old environment APIs (#3634)
I was perusing the code whilst investigating #3606 and noticed that,
despite the release post claiming that Fresh had ["fully
embrace[d]"](https://deno.com/blog/fresh-and-vite#:~:text=fully%20embraces)
the Vite Environment API, it was still using `ssrLoadModule`. Once I
started looking, I noticed a bunch of other code that wasn't
future-proof (env-wise, not rolldown-wise, which'll bring it's own swath
of deprecations[^1]), so I updated them as well.

The newly added source map tests from #3624 currently fail again because
the ModuleRunner API at the heart of the Environment API relies on
[`process.setSourceMapsEnabled`](https://docs.deno.com/api/node/process/~/Process.setSourceMapsEnabled),
which is [currently set to
no-op](https://github.com/denoland/deno/pull/22993) in Deno.

[^1]: Separately tried to try out rolldown-vite but it seems that Deno
doesn't support aliasing dependencies whatsoever? (I know there's not
official support, but I was going to try to edit the lockfile to hack
around it; however, it seems that there's not alias support in there at
all?)
2025-12-09 13:00:36 +01:00
David Sherret 18e47a86b0 fix(vite): force at least @deno/loader@0.3.10 (#3631)
Ref: https://github.com/denoland/deno-js-loader/pull/68
2025-11-19 23:05:45 +01:00
Marvin Hagemeister 2c36becff0 chore: release 2.2.0 (#3627)
- `@fresh/core@2.2.0`
- `@fresh/update@2.2.0`
- `@fresh/init@2.3.0`
- `@fresh/plugin-vite@1.0.8`
2025-11-18 14:09:19 +01:00
Marvin Hagemeister f5c0f16878 fix(vite): source mapping locations (#3624)
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
2025-11-18 11:40:52 +01:00
Christian Svensson 1dd8279075 docs(vite): add JSDoc and export public API (#3604)
Improves documentation of `@fresh/plugin-vite` related to public API,
and exports missing symbols/types that are part of public API
(`FreshViteConfig`).

- Adds `@module` JSDoc for the `@fresh/plugin-vite/client` entrypoint
  - Internal only, used for browser HMR
- Exports types `ImportCheck` & `ImportCheckDiagnostic`, as they are
part of the public API via `FreshViteConfig`
- Should make [`ImportCheck` link to correct
type](https://jsr.io/@fresh/plugin-vite/doc/~/FreshViteConfig#property_checkimports):
<img width="1053" height="285" alt="image"
src="https://github.com/user-attachments/assets/766c29f7-7f39-429e-bd81-234fed6b0820"
/>
- Adds JSDoc descriptions for all public exports; `fresh`,
`FreshViteConfig`, `ImportCheck` & `ImportCheckDiagnostic`
- Adds description for `FreshViteConfig.checkImports`

Part of #3597 & #3596
2025-11-11 15:33:03 +01:00
Marvin Hagemeister 42d7d9f23b chore: release 2.1.4 (#3586)
- @fresh/core@2.1.4
- @fresh/update@2.1.4
- @fresh/init@2.2.2
- @fresh/plugin-vite@1.0.7
2025-10-30 15:57:14 +01:00
PastelStoic c7af11eb7c fix(vite): inherit top level outDir configuration for builds (#3570)
The Vite outDir setting is confusingly ignored, which is not documented
in the plugin documentation. This corrects that, while still preferring
the more specific environment settings.
2025-10-30 14:55:29 +01:00
Marvin Hagemeister 7b6d6315d1 fix(vite): mark transformed cjs with __esModule (#3575)
Fixes https://github.com/denoland/fresh/issues/3565
2025-10-24 19:54:37 +02:00
Marvin Hagemeister 5a228625ea chore: release 2.1.3 (#3572)
- @fresh/core@2.1.3
- @fresh/update@2.1.2
- @fresh/plugin-vite@1.0.6
- @fresh/init@2.2.1
2025-10-23 13:15:07 +02:00
PastelStoic 07f74ffa4a fix: link to Fresh documentation in README (#3569) 2025-10-23 12:29:49 +02:00
Brett Chalupa de1810e70d fix(vite): exclude test files from production builds (#3559)
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
2025-10-21 11:26:20 +02:00
Marvin Hagemeister 8b7caba444 chore: release 2.1.2 (#3542)
- @fresh/core@2.1.2
- @fresh/update@2.1.2
- @fresh/plugin-vite@1.0.5
2025-10-08 12:56:08 +02:00
Marvin Hagemeister efef51714b fix(vite): unable to load transpiled commonjs with node builtins (#3541) 2025-10-08 12:47:04 +02:00
Marvin Hagemeister 4b069ee0d0 fix(vite): empty commonjs files with only __esModule (#3540)
When modules only contain the `__esModule` flag, we still need to add
the `exports` and `module.exports` initializers.
2025-10-08 11:50:34 +02:00
Marvin Hagemeister 6c03a9bc26 fix(vite): support jsx namespaces (#3539)
Babel throws when encountering jsx namespaces by default. It needs a
setting to not throw.
2025-10-08 11:30:07 +02:00
fry69 84576bd848 fix: prevent island names from shadowing JavaScript globals (#3522)
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.
2025-10-05 10:53:55 +02:00
David Sherret a45cfe1ced fix(docs): export FreshViteConfig type (#3516)
For https://jsr.io/@fresh/plugin-vite/doc/~/fresh
2025-10-03 19:59:34 +02:00
Marvin Hagemeister 63dd77a319 fix(vite): dev server not recovering on syntax error (#3507)
Fixes https://github.com/denoland/fresh/issues/3506
2025-09-29 19:03:02 +02:00
fry69andMarvin Hagemeister f7a2422e93 fix: set nodeModulesDir to manual (#3493)
Hopefully a less invasive fix for #3378

---------

Co-authored-by: Marvin Hagemeister <hello@marvinh.dev>
2025-09-25 20:54:27 +02:00
Marvin Hagemeister 5c05d6533f chore: release 2.1.1 (#3466)
- @fresh/core@2.1.1
- @fresh/update@2.1.1
- @fresh/plugin-vite@1.0.4
2025-09-19 20:27:35 +02:00
Marvin Hagemeister 9b83a1e1b3 fix(vite): cover more commonjs cases (#3465)
Fixes https://github.com/denoland/fresh/issues/3463
Fixes https://github.com/denoland/fresh/issues/3449
2025-09-19 18:36:51 +02:00
Marvin Hagemeister 69ad9bc3c1 fix(vite): improve cjs esm detection + builtins resolution (#3457) 2025-09-16 19:41:22 +02:00
Marvin Hagemeister 9a2098ecba fix(vite): ensure plugins are only instantiated once (#3450)
This makes debugging a lot easier as by default vite instantiates
plugins multiple times for each environment.
2025-09-16 11:35:00 +02:00
Marvin Hagemeister de9b8a7c40 chore: release 2.1.0 (#3443)
- @fresh/core@2.1.0
- @fresh/plugin-vite@1.0.3
- @fresh/update@2.1.0
- @fresh/init@2.0.9
2025-09-15 19:29:04 +02:00
Marvin Hagemeister 399cbc3aa2 fix(vite): nested islands not working (#3440)
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
2025-09-15 17:55:44 +02:00
Marvin Hagemeister 3fb3cd9443 fix(vite): route css import (#3438)
Fixes https://github.com/denoland/fresh/issues/3426
2025-09-15 13:20:07 +02:00
Marvin Hagemeister f9ba5417c4 fix: bring back support for middleware Array (#3434)
Our validation didn't account for `_middleware` files exporting an Array
of middlewares.

Fixes https://github.com/denoland/fresh/issues/3400
2025-09-15 10:44:21 +02:00
Marvin Hagemeister b31f36265c fix(vite): keep require calls in ESM file (#3433)
Detect if a file is ESM based on file extension or finding ESM-only
statements. When we know that it's an ESM file we should keep
`require()` calls as is, because some libraries use it as a conditional
check like `npm:motion`.

Fixes https://github.com/denoland/fresh/issues/3429
2025-09-15 10:40:09 +02:00
Marvin Hagemeister 4cc0722465 chore: release 2.0.2 (#3418)
- @fresh/core@2.0.2
- @fresh/plugin-vite@1.0.2
- @fresh/update@2.0.2
- @fresh/init@2.0.8
2025-09-12 19:16:12 +02:00
Marvin Hagemeister ae3db58a99 fix(vite): .env files not being loaded (#3416)
Fixes https://github.com/denoland/fresh/issues/3364
2025-09-12 18:21:51 +02:00
LachandMarvin Hagemeister dd41a8706b fix(vite): exclude packages from deno cache in prefresh (#3374)
When disabling `node_modules` directory in Deno, prefresh plugin
transforms files in ~/.cache/deno/npm/registry.npmjs.org/ directory,
causing an arcane error to occur:
https://github.com/preactjs/prefresh/issues/124

After disabling this transform my site now works on updated fresh
version

I'm not sure if is the correct way to exclude this, but I don't see any
longer pattern that would work here

The cache is stored in $XDG_CACHE_HOME/deno/npm/$REGISTRY_HOST, where
only deno/npm part seems to be static

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-09-12 18:17:36 +02:00
Marvin Hagemeister 8a996a428a fix(vite): missing build id in Deno Deploy EA (#3414)
Fixes https://github.com/denoland/fresh/issues/3282
2025-09-12 15:24:26 +02:00
Marvin Hagemeister e06f03ac67 fix: add missing compile entry (#3410)
Fixes https://github.com/denoland/fresh/issues/3409
2025-09-12 13:08:49 +02:00
Marvin Hagemeister 7ce6aeff8b fix(vite): workaround for FOUC with tailwind (#3407)
Fixes https://github.com/denoland/fresh/issues/3379
2025-09-12 12:34:23 +02:00
Marvin Hagemeister e5bc9194e9 fix(vite): drop trailing or leading whitespace in build id (#3408)
Fixes https://github.com/denoland/fresh/issues/3406
2025-09-12 12:33:13 +02:00
Marvin Hagemeister 0e6bddd06e chore: release 2.0.1 (#3404)
- @fresh/core@2.0.1
- @fresh/plugin-vite@1.0.1
- @fresh/update@2.0.1
- @fresh/init@2.0.7
2025-09-12 11:05:03 +02:00
Marvin Hagemeister 9581d7e6d4 fix(vite): remove Deno global check (#3401)
Ultimately, it causes more problems than it solves.
2025-09-12 10:01:37 +02:00
fry69 6fbe0ddcc4 fix(vite): basePath handling for static assets (#3394)
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.
2025-09-11 16:07:15 +02:00
Marvin Hagemeister fb341e4ab7 chore: release 2.0.0 (#3371) 2025-09-09 18:52:36 +02:00
Marvin Hagemeister f773d0d359 feat(vite): add update checker (#3372) 2025-09-09 18:52:19 +02:00
Lach 5781123157 fix(vite): allow optional property access to Deno global (#3370)
Ideally, those expressions should be replaced with undefined for better
code optimizations, yet I haven't figured it out the best way for this.

Fixes:
https://github.com/denoland/fresh/issues/3296#issuecomment-3270452525
2025-09-09 15:17:36 +02:00
Marvin Hagemeister cb14abad21 chore: release @fresh/plugin-vite@0.10.2 (#3366) 2025-09-08 22:12:54 +02:00
Marvin Hagemeister 69283c81b4 chore: release @fresh/plugin-vite@0.10.1 (#3361) 2025-09-08 18:00:06 +02:00
Marvin Hagemeister be2fde6a85 fix(vite): silence optional export warnings (#3360)
Seems like vite is overly strict when accessing optional namespaced
module properties. The code is perfectly fine, so silence these
warnings.
2025-09-08 17:59:54 +02:00
Marvin Hagemeister 2c2257843e chore: release @fresh/plugin-vite@0.10.0 (#3359) 2025-09-08 17:43:07 +02:00
Marvin Hagemeister 8743322968 feat(vite): serve static index.html files (#3358)
Fixes https://github.com/denoland/fresh/issues/3356
2025-09-08 17:36:30 +02:00