Commit Graph
38 Commits
Author SHA1 Message Date
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
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
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
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 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
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 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 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
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 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 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
Marvin Hagemeister 2e015cd2b9 fix(vite): improve commonjs handling (#3357) 2025-09-08 17:06:11 +02:00
Marvin Hagemeister 2c32ffe8f3 fix(vite): support ssr css modules (#3355)
Fixes https://github.com/denoland/fresh/issues/3325
2025-09-08 16:23:13 +02:00
Marvin Hagemeister 4ff8e677aa fix(vite): nested island css module styles not working (#3353)
Related https://github.com/denoland/fresh/issues/3325
2025-09-08 10:00:14 +02:00
Marvin Hagemeister 185ab95751 fix(vite): get radix-ui working (#3344) 2025-09-05 16:51:22 +02:00
Marvin Hagemeister 4138b8ca66 fix(vite): improve commonjs handling (#3336)
Fixes https://github.com/denoland/fresh/issues/3323
2025-09-04 12:59:13 +02:00
Marvin Hagemeister 08ef05fc1d fix(vite): pathname treated as static file (#3326)
Fixes https://github.com/denoland/fresh/issues/3322
2025-09-03 11:34:19 +02:00
Marvin Hagemeister ae2a27e174 feat(vite): error when using Deno global in the browser (#3305)
Related https://github.com/denoland/fresh/issues/3296
2025-09-01 19:56:31 +02:00
Marvin Hagemeister ff9db336f7 feat(vite): check valid imports per environment (#3299)
Fixes https://github.com/denoland/fresh/issues/3296
2025-09-01 17:30:30 +02:00
Marvin Hagemeister 541bc6c6ca feat(vite): support remote islands (#3294) 2025-09-01 12:11:08 +02:00
Marvin Hagemeister b41c151de3 fix(vite): serve css imported in islands (#3272)
Fixes https://github.com/denoland/fresh/issues/3271
2025-08-29 14:30:00 +02:00
Marvin Hagemeister 7afae637fe chore: simplify fallback rendering (#3262) 2025-08-26 14:38:44 +02:00
Marvin Hagemeister adc5c2e4a8 chore: speed up vite tests (#3258) 2025-08-26 09:52:26 +02:00
Marvin Hagemeister d1f7d49466 fix(vite): importing node:* builtins (#3245) 2025-08-22 13:58:39 +02:00
Marvin Hagemeister 5c3fe27046 chore: refactor tests (#3243) 2025-08-22 12:14:19 +02:00
Marvin Hagemeister 27c2910b1d fix(vite): babel transform being applied for non-js files (#3238) 2025-08-21 20:03:00 +02:00
fry69andMarvin Hagemeister 9f09786b06 feat(vite): read build id from env if present (#3233)
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>
2025-08-21 13:31:45 +02:00
Marvin Hagemeister ffa57be765 fix(vite): partial island loading (#3226) 2025-08-19 17:58:17 +02:00
Marvin Hagemeister afdf5eaf6c fix(vite): asset handling (#3225)
This PR reworks asset handling in our vite plugin. Importing assets in
js is now supported.
2025-08-19 16:45:33 +02:00
Marvin Hagemeister f80d049dca fix(vite): inline FRESH_PUBLIC_* env vars (#3221) 2025-08-16 23:14:03 +02:00
Marvin Hagemeister d026375c3e fix(vite): error when npm package requires json files (#3210) 2025-08-08 14:16:38 +02:00
Marvin Hagemeister 22ebb2dbfa fix: support optional static, routes and island dir in vite plugin (#3206) 2025-08-08 09:23:38 +02:00
Marvin Hagemeister 815b1940e3 chore: restructure repository into packages/ folder (#3197)
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.
2025-08-06 15:52:45 +02:00