Commit Graph
39 Commits
Author SHA1 Message Date
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
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 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ń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 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 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
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
Bartek IwańczukandClaude Opus 4.6 e0ee53d458 fix: dev server intercepts Vite URLs when basePath is configured (#3730)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 19:42:36 +00:00
a79b155e79 fix: make <Head> work in client (#3252)
Closes #3310

---------

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:21:39 +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
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
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
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 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 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 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 27c2910b1d fix(vite): babel transform being applied for non-js files (#3238) 2025-08-21 20:03:00 +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