Commit Graph
540 Commits
Author SHA1 Message Date
Christian Svensson b852fe7deb fix: log warning on invalid route configurations (#2954)
Related to #2953.

I found it confusing that there were unsupported route configurations,
that fails silently without any errors or wanings. Though I think it is
a good idea to not throw for this, as that would be worse DX. But
logging a warning if the developer is migrating from Fresh v1, or if the
developer is using code that will not work (e.g. copy pasting a handler
from a route to `_middleware`), I think it's helpful where reasonable to
help guide a bit more.

Does a small refactor first to hopefully improve typing to be more
correct for `InternalRoute.handlers`, then adds warnings for the
following:

- `_middleware` using Object form (`GET`, `POST` handlers) of the
handler format
  - Helps find issues when moving handler from route to middleware
- `_layout` using `handlers`
  - E.g. if developer moves a route to a layout
- ~~`_404`, `_500` or `_error` using Object handler form (`GET`, `POST`
handlers), which is not yet supported (See #2953)~~
  - No longer necessary as it is fixed by #2955
2025-05-15 17:09:53 +02:00
Asher Gomez 20162f6896 chore: use lint tags (#2952) 2025-05-15 09:34:46 +02:00
Marvin Hagemeister 36442d0ded fix(core): silence esbuild jsx comment warning (#2944)
JSR is a bit over-eager with inserting JSX comments and inserts both
`@jsx classic` and `@jsxImportSource` which are ignored in combination

Fixes https://github.com/denoland/fresh/issues/2942
2025-05-14 22:45:04 +02:00
Christian Svensson e2d0624512 fix: do not skip app-wrapper for sibling routes (#2911)
This PR adds a unit test for the issue in #2910. I have not found a
solution yet, since I'm not very familiar with the `fsRoutes` code, and
what it is doing. But a thought a unit test with the failing code could
help to find a bug fix.

**Edit:** I managed to fix the failing test by removing a couple of
lines, but I'm not too familiar with the code so I'm not sure if it's
correct. It seems to pass all the tests still...

Closes #2910
2025-05-13 18:03:13 +02:00
Christian Svensson f15f225576 fix: make static folders with dot such as .well-known allowed (#2929)
This PR intends to address an error logged when opening a DevTools in a
Chromium based browser while using Fresh in dev mode.

<details>

<summary><strong>See error</strong></summary>

```
Error: Processed file resolved outside of static dir C:\Users\<name>\fresh-site\src\static\.well-known\appspecific\com.chrome.devtools.json
    at MemoryBuildCache.readFile (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/dev/dev_build_cache.ts:81:13)
    at eventLoopTick (ext:core/01_core.js:178:7)
    at async freshStaticFiles (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/static_files.ts:30:18)
    at async FreshReqContext.fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async https://jsr.io/@fresh/core/2.0.0-alpha.29/src/dev/middlewares/error_overlay/middleware.tsx:15:14
    at async FreshReqContext.fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async fn (https://jsr.io/@fresh/core/2.0.0-alpha.29/src/middlewares/mod.ts:99:18)
    at async https://jsr.io/@fresh/core/2.0.0-alpha.29/src/app.ts:232:16
    at async mapped (ext:deno_http/00_serve.ts:407:18)
```

</details>

DevTools tries to load a
`<root>/static/.well-known/appspecific/com.chrome.devtools.json` file,
which incorrectly is flagged as "outside" the static directory, and thus
generates errors instead of 404.

Maybe hidden folders (starting with `.`) in `/static` should be opt-in
though? I'm not sure if anyone puts folders with `.` prefix inside
`static/` without intending them to be accessible?

- `..` throws errors (outside staticDir)
- `.` returns "missing file" (unless `config.allowHiddenFolders` is
true)

## Automatic workspace folders

I think a follow-up PR could be for the Dev `Builder` to also implement
support for [Automatic workspace
folders](https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md),
by returning JSON content automatically at
`.well-known/appspecific/com.chrome.devtools.json`.

I think a good first step is to allow `.<folder-name>`, especially since
`.well-known/` has [many valid
use-cases](https://en.wikipedia.org/wiki/Well-known_URI), and as such is
not unreasonable to want to add static files in.
2025-05-13 10:03:05 +02:00
Marvin Hagemeister fcd94809c8 fix(esbuild): disable spammy warning for monaco editor (#2928)
It's a super spammy warning message when you're using the monaco editor.
They have code like that as the result of minifcation.

Fixes https://github.com/denoland/fresh/issues/2775
2025-05-13 00:13:21 +02:00
Marvin Hagemeister d2da471d67 fix(partial): form dialog method not supported (#2927)
The `<form>` method value `dialog` does no network request, so we should
ignore it for partials.

Fixes https://github.com/denoland/fresh/issues/2885
2025-05-12 21:19:19 +02:00
Marvin Hagemeister 24ad244a79 fix: error when no Response instance is returned (#2924)
Fixes https://github.com/denoland/fresh/issues/1494
2025-05-12 20:30:45 +02:00
Marvin Hagemeister 09705b9b7f fix: bigint key values erroring (#2923)
Fixes https://github.com/denoland/fresh/issues/2802
2025-05-12 19:49:13 +02:00
Tim Reichen 1cfb4bc876 refactor: make App.prototype.handler() sync (#2906) 2025-05-12 10:12:50 +02:00
Tim Reichen 9605cd81b5 refactor: move mergePaths() to utils.ts (#2905) 2025-05-12 09:59:37 +02:00
Tim Reichen c6d4c47e00 refactor: App.prototype.listen() (#2907) 2025-05-12 09:58:37 +02:00
Christian Svensson c0e2b80690 fix: allow relative paths for outDir and staticDir (#2914)
This PR consists of several commits, where the goal is to re-enable the
test (fix for Windows), as well as allow relative paths for config
options to address #2913.

1. Re-enables test and normalizes paths for Windows
2. Add unit test for `normalizeConfig` and the `root` option
3. Add unit test for `normalizeConfig` for `build.outDir` and
`staticDir`, and allow the properties to be relative
4. Add JSDoc for fields in `FreshConfig`

I can split these into separate PR's if preferred, but all code changes
are very in nearly the same places.

Closes #2913
2025-05-12 09:43:01 +02:00
Christian Svensson d10ea5a89a fix: remove unnecessary config property in init script (#2915)
From what I can see, `fsRoutes` uses the `FreshConfig.root` option by
default, so this property does not need to be specified. I also added
some JSDoc for the `dir` option in `fsRoutes()` as I understood it's
purpose.
2025-05-12 09:42:16 +02:00
Christian Svensson a23596153b fix: allow Data to be inferred from Handler function (#2916)
This PR adds support for single-function GET handler data to be inferred
when using `define.page<typeof handler>()`.

```ts
export const handler = define.handlers((ctx) => {
  return page({ foo: "foo" });
});

export default define.page<typeof handler>((ctx) => {
  ctx.data; // Correctly resolves as { foo: string }
});
```

This PR also adds a test that checks that the types inferred are correct
by type checking.
2025-05-12 09:41:28 +02:00
Marvin Hagemeister f9bfecab8e fix(builder): css hash incorrectly transforming data urls (#2921)
Fixes https://github.com/denoland/fresh/issues/2599
2025-05-12 09:40:35 +02:00
Asher Gomez e0ca9423d9 BREAKING(core): remove Mode type (#2884)
It doesn't seem like it deserves to be it's own type. It can just be an
interface property.
2025-05-05 08:40:34 +02:00
Asher Gomez 45ce7e3ac0 chore: add doc checker (#2877)
First steps towards #2876
Depends on https://github.com/denoland/std/pull/6632
2025-05-02 10:55:55 +02:00
Asher Gomez 51e4d334af refactor(core): remove unused constants (#2872) 2025-04-30 10:32:19 +02:00
Asher Gomez b582c57e57 refactor(core): use getSnapshotPath() (#2873) 2025-04-30 10:31:47 +02:00
Asher Gomez 7aec5a268e refactor(core): standardize HttpError (#2858)
- Now extends `Error`, so that it satisfies `instanceof Error`
operations.
- Narrows the `status` property to be an actual HTTP status code.
- Outsources default evaluation of the `message` property to
`@std/http/status`, which already implements this functionality.
- Brings the `stack` property to the class, regardless of its status,
which seems like a needless constraint.
2025-04-27 20:01:31 +02:00
Asher Gomez 5876ca7752 chore: remove prettyTime() (#2859)
This isn't used anywhere.
2025-04-27 19:59:07 +02:00
Luca Casonato b4fd717c6c fix: reset span name and http.route in static file middleware (#2856) 2025-04-23 14:35:39 +02:00
Tim Reichen bbfea7538b fix: b64encode param type (#2832) 2025-03-05 12:32:24 +01:00
Tim Reichen 0a634bd2d2 chore: fix lint errors (#2833)
This PR fixes current lint errors thrown by `deno lint`.
2025-03-05 12:31:25 +01:00
Marvin Hagemeister f245471ddf fix: route middleware order with groups (#2811)
This is a follow-up fix to https://github.com/denoland/fresh/pull/2792

The original fix skipped over route groups which lead to them being
mixed with non-grouped routes. This in turn confused the middleware
processing part when building the final routes.
2025-01-16 21:57:42 +01:00
Paul Carduner 2baf6dc7a0 fix: middlewares not being used with default GET handlers (#2807)
I noticed a small bug with the default GET handlers where middlewares
were not being run. This pull requests fixes the bug and adds some unit
tests for this behavior.
2025-01-09 00:09:26 +01:00
Marvin Hagemeister 70d6cbd1e5 fix(router): exclude route groups in scoring for sorting (#2792)
This PR fixes an issue in the route sorting logic when comparing a route
segment with a group vs a segment without one.

- `/(app)/[org]/[app]/index.ts`
- `/auth/login.ts`

When determing the order of these two routes we need to skip over the
`(app)` group to the next non-group segment. This ensures that we are
only scoring actual segments with each other and non-existing ones.
2024-12-16 14:14:52 +01:00
Luca Casonato ae9c675384 fix: correctly serialize negative numbers (#2790)
This commit fixes a bug where negative numbers were not correctly
serialized, because the value parser confused "references" (which is
where special negative tokens for special values exist), and "values"
(where negative numbers are just negative numbers). The parser now
correctly distinguishes between the two.
2024-12-11 20:13:22 +01:00
Luca Casonato 65d61bd1d5 feat: add open telemetry instrumentation (#2786)
This commit adds some useful automatic instrumentation for when users
are using `--unstable-otel`:

- Fresh renames the span for incoming HTTP requests to `$METHOD $ROUTE`
and the `http.route` attribute is added.
- Fresh creates a span around FS route handlers, showing whether they
returned a response or data.
- Fresh creates a span around async components, showing how long they
took to execute.
- Fresh adds a span around preact rendering, showing how long rendering
takes.
- Fresh adds a span around static file serving, showing how long it took
and whether there were requests without a cache bust key.

We can improve this in the future with more telemetry, such as metrics.
2024-12-10 15:03:50 +01:00
Luca Casonato 6b685dde9f fix: serve internal JS from path containing build ID (#2753)
Previously imported chunks were not cached at all. They are now cached
properly with immutable cache headers.
2024-11-08 11:44:15 +01:00
Luca Casonato 8ced083267 fix: serialization of signals containing null and undefined values (#2744) 2024-10-31 11:22:03 +01:00
Luca CasonatoandMarvin Hagemeister 407987589f feat: support fresh projects that are part of a workspace (#2716)
Also a performance improvement & bug fix in the tailwind plugin.

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2024-10-17 17:08:24 +02:00
Christian Svensson 628832af0f fix: ensure file paths in snapshot.json uses / (#2704)
Avoids `\\\\` paths ending up in `snapshot.json` when using `deno task
build` on Windows. Backslashes do not which pathnames in URLs, so these
assets are not returned.

Closes #2703
2024-10-15 11:29:35 +02:00
Marvin Hagemeister a596a04258 fix: SVG in links breaking partials (#2681)
Fixes https://github.com/denoland/fresh/issues/2239
2024-10-04 08:08:18 +02:00
Marvin Hagemeister 5f657478aa fix: middleware default export ignored (#2680)
Fixes https://github.com/denoland/fresh/issues/2657
2024-10-04 06:56:52 +02:00
Marvin Hagemeister ea3df041c1 Fix: prepare URLPattern spec change (#2676)
Fixes https://github.com/denoland/fresh/issues/2627
2024-10-04 05:15:43 +02:00
Marvin Hagemeister 75b5854810 fix: nested children slots erroring (#2674)
Fixes https://github.com/denoland/fresh/issues/2624
2024-10-04 05:05:27 +02:00
Marvin HagemeisterandLuca Casonato de8f1b0c59 feat: update for Deno 2 (#2655)
Co-authored-by: Luca Casonato <hello@lcas.dev>
2024-09-30 18:30:30 +02:00
Felix 126f492ea0 fix: decode static file paths (#2642)
Fixes #2613
2024-09-06 10:49:07 +02:00
Luca CasonatoandMarvin Hagemeister 1f9fb91c4d fix: add proper cache control headers (#2617)
The whole point of `asset()` is to enable caching. Yet we were not
adding cache control headers... :D

---------

Co-authored-by: Marvin Hagemeister <marvin@deno.com>
2024-08-13 14:15:25 +02:00
Marvin Hagemeister b510113655 fix: include middlewares and layouts for error pages (#2598)
Fixes https://github.com/denoland/fresh/issues/2594
2024-07-16 10:53:38 +02:00
Reed von Redwitz 8413666786 fix: support numeric keys when rendering (#2584)
I'm trying to migrate one of my projects which publishes a plugin, and
this was blocking me.

Looks like key is typed as `export type Key = string | number | any;`,
so we might need to make more changes here in the future.
2024-07-07 19:09:11 +02:00
Marvin Hagemeister 6be6435467 fix: missing dom root frag polyfill after preact update (#2569) 2024-07-03 10:39:33 +02:00
Marvin Hagemeister 79a262b344 fix: GET partial form submit ignoring multiple checkbox values (#2568)
Fixes https://github.com/denoland/fresh/issues/2567
2024-07-02 22:24:48 +02:00
Marvin Hagemeister 138d4c457c fix: remove unnecessary URL allocation (#2554) 2024-06-27 12:34:56 +02:00
Marvin Hagemeister becd440d77 fix: error bundling JSR islands (#2552) 2024-06-26 16:55:26 +02:00
Marvin Hagemeister fc820e8965 feat: add error messages for missing build cache (#2551) 2024-06-26 15:33:25 +02:00
Marvin Hagemeister 72811da29b fix: etag caching HTTP headers (#2504) 2024-06-25 10:21:43 +02:00
Marvin Hagemeister 0f6b4f624f chore: remove debug trace logs (#2545) 2024-06-25 10:08:48 +02:00