Commit Graph
1578 Commits
Author SHA1 Message Date
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
Zhi 7999d500f8 docs: fix missing files on "sharing state with islands" page (#3377)
close #3376
2025-09-12 17:16:30 +02:00
Marvin Hagemeister 169f156f78 fix(init): incorrect target dir argument (#3415)
Fixes https://github.com/denoland/fresh/issues/3413
2025-09-12 15:37:06 +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 fc3cdc9588 docs: update cloudflare workers docs (#3405) 2025-09-12 11:04:47 +02:00
Marvin Hagemeister e30cb375d1 docs: mention entry in cloudflare worker docs (#3403)
Related https://github.com/denoland/fresh/issues/3402
2025-09-12 10:37:38 +02:00
fry69 3010e27097 fix: add basePath support in mountApp() (#3395)
Fix for mountApp() with the new basePath handling

---
Generated PR message:

I successfully investigated and implemented a fix for mountApp() to make
it compatible with basePath handling. Here's what I found and fixed:

  The Problem

The original mountApp() implementation completely ignored the inner
app's basePath. When mounting an app like this:

```ts
  const innerApp = new App({ basePath: "/api" })
    .get("/users", () => new Response("users"));

  const app = new App()
    .mountApp("/v1", innerApp);
```

The route would become /v1/users instead of the expected /v1/api/users
because the inner app's /api basePath was lost.

  Root Cause

The issue was in the mountApp() method at packages/fresh/src/app.ts:333.
The original code only used:

```ts
  pattern: mergePath(path, cmd.pattern, true)
```

This only considered the mount path (/v1) and the command pattern
(/users), but ignored app.config.basePath (/api).

  The Fix

I modified the mountApp() method to properly handle the inner app's
basePath:

```ts
  // Apply the inner app's basePath if it exists
  let effectivePattern = cmd.pattern;
  if (app.config.basePath) {
    effectivePattern = mergePath(app.config.basePath, cmd.pattern, false);
  }

  const clone = {
    ...cmd,
    pattern: mergePath(path, effectivePattern, true),
    includeLastSegment: cmd.pattern === "/" || cmd.includeLastSegment,
  };
```

The key insight was to only apply the basePath transformation when the
inner app actually has a basePath (not empty), which preserves backward
  compatibility with existing code that doesn't use basePath.

  Test Coverage

  I added comprehensive test cases covering:

1. Inner app with basePath: /v1 + /api basePath + /users route =
/v1/api/users
2. Main app with basePath + mounted app: /main basePath + /sub mount +
/data route = /main/sub/data
3. Both main and inner basePath: /main + /services + /api/v2 + /users =
/main/services/api/v2/users

  Backward Compatibility

  The fix maintains full backward compatibility:
  - ✅ All existing mountApp() tests pass
  - ✅ All existing basePath tests pass
  - ✅ New functionality works as expected

  Now the three basePath mechanisms work correctly together:

  1. Vite base config → Static asset URLs
  2. App basePath option → Route matching (now works with mountApp!)
  3. External mounting → Framework integration

The solution correctly handles the scenario you described where
vite.config.ts, main.ts, and external mounting all work together
seamlessly.
2025-09-12 10:06:06 +02:00
Christian Svensson 6466c975d5 fix: show help text and refresh help formatting (#3399)
- Show help text when `-h` or `--help` is passed to `@fresh/init`
- Print current version for `@fresh/init` during `--help`
<img width="367" height="95" alt="image"
src="https://github.com/user-attachments/assets/e3318fae-ce8a-4cbb-bb0a-78f338f1b3a2"
/>
- Refresh `--help` text with colors similar to `deno -h`; + "Fresh
branding" style for the `@fresh/init` text
- Print `@fresh/core` version when `@fresh/init` runs
<img width="471" height="88" alt="image"
src="https://github.com/user-attachments/assets/1a0bd619-315d-4abb-889c-ec6eb3a9b45f"
/>

I think showing versions is helpful for verifying/debugging what Fresh
version will be installed during init before all files are generated.

## Comparisons

### `@fresh/init` + empty project name

#### Before

<img width="1104" height="615" alt="image"
src="https://github.com/user-attachments/assets/b1534bb5-eecc-4692-9977-df3903868416"
/>

#### After

<img width="1169" height="695" alt="image"
src="https://github.com/user-attachments/assets/6a743d79-bb59-463a-aadd-fbf734149258"
/>

### `@fresh/init --help`

#### Before

<img width="1007" height="150" alt="image"
src="https://github.com/user-attachments/assets/0ad42078-420c-4dc6-9561-4a338cc09741"
/>

#### After

<img width="1272" height="579" alt="image"
src="https://github.com/user-attachments/assets/3dfe6712-8604-4429-a418-5e6538117303"
/>
2025-09-12 10:04:54 +02:00
fry69 a473cc9d9f docs: update testing with routes and islands (#3385)
closes #3383
2025-09-12 10:03:08 +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
Christian Svensson c22c20e21f docs: avoid showing "Copied" if copying fails (#3397)
I noticed that in denoland/fresh#3393 it looks like it's possible that
the "Copied"/Check icon will be shown even if copying to clipboard
fails.

This PR changes it so that the Check icon only shows if copy succeeds.
2025-09-11 21:37:31 +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 554644b240 docs: add copy buttons (#3393) 2025-09-11 15:19:34 +02:00
fry69 a7af5c0c3d docs: add simple mountApp example (#3380)
Simple `mountApp()` example from the Discord
2025-09-10 13:41:39 +02:00
fry69 db5b2a3b82 fix: add route type to props (#3382) 2025-09-10 10:58:23 +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 79d8cfc3ed docs: make 2.x the default version (#3369) 2025-09-09 14:36:51 +02:00
Marvin Hagemeister 2c315a9972 docs: remove outdated crud docs (#3368)
Fixes https://github.com/denoland/fresh/issues/3367
2025-09-09 11:59:34 +02:00
Marvin Hagemeister cb14abad21 chore: release @fresh/plugin-vite@0.10.2 (#3366) 2025-09-08 22:12:54 +02:00
Marvin Hagemeister 6e9f586c54 chore: release 2.0.0-beta.5 and @fresh/plugin-vite@0.10.2 (#3365)
Fixes https://github.com/denoland/fresh/issues/3363
2025-09-08 22:07:49 +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
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 4c3ff9b74d chore: fix demo tasks (#3354) 2025-09-08 15:43:07 +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
ZhiandMarvin Hagemeister f869bff685 docs: fix typos in image filenames and update references (#3348)
Fix typos in image filenames and update references
#3340 Inconsistent renaming caused images to fail normal detection.

---------

Co-authored-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
2025-09-06 17:39:04 +02:00
Alejandro Martínez 2d3f28a960 docs: include missing imports in the getting started tutorial (#3349)
The Countdown code in the tutorial doesn't work when copied and pasted
because the imports for useSignal and useEffect are missing. Adding the
missing imports will help those following the tutorial to have a better
experience.
2025-09-06 10:32:22 +02:00
Marvin Hagemeister a72472095d chore: releasd @fresh/plugin-vite@0.9.13 (#3345) 2025-09-05 16:58:27 +02:00
Marvin Hagemeister 185ab95751 fix(vite): get radix-ui working (#3344) 2025-09-05 16:51:22 +02:00
Marvin Hagemeister b06ef5a855 chore: release 2.0.0-beta.4 and @fresh/plugin-vite@0.9.12 (#3343) 2025-09-05 12:23:47 +02:00
Marvin Hagemeister a892da2b0e fix(vite): incorrect JSX detection (#3342) 2025-09-05 12:17:12 +02:00
ZhiandMarvin Hagemeister 7c5f209296 docs: add images to getting started guide (#3340)
Replaced placeholder TODOs with actual screenshots in the getting
started documentation and added three new image files to illustrate the
initialization, about page, and countdown examples.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2025-09-05 12:13:32 +02:00
Marvin Hagemeister 971163ff66 fix: account for JS syntax when generating island names (#3341)
Fixes https://github.com/denoland/fresh/issues/3339
2025-09-05 11:33:50 +02:00
Marvin Hagemeister 892aefbf94 chore: release @fresh/plugin-vite@0.9.11 (#3337) 2025-09-04 13:06:50 +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 b94aab2a1a chore: update to vite's hook filter (#3333)
Fixes https://github.com/denoland/fresh/issues/3331
2025-09-04 11:16:06 +02:00
Marvin Hagemeister baf774517b chore: get builds passing in Deno canary (#3335) 2025-09-04 10:18:17 +02:00
Marvin Hagemeister e21d6742d2 chore: add demo tasks (#3332) 2025-09-03 18:52:19 +02:00
Marvin Hagemeister 70017d2480 docs: fix form data page (#3329)
Fixes https://github.com/denoland/fresh/issues/3320
2025-09-03 12:12:53 +02:00
Marvin Hagemeister cc004a5efa chore: release @fresh/init@2.0.5 (#3328) 2025-09-03 12:06:12 +02:00