Preact, like most other popular frameworks disallows passing stringified
JavaScript code as event handlers. We have one occurrence of that in our
doc search. The recent addition of including `preact/debug` during
server rendering in #1256 surfaced this problem.
This PR works around that by injecting a tiny script tag that attaches
the event handler. Basically only a slightly different approach than
before.
This can be useful when deploying to other providers.
Also more convenient for projects with multiple developers with port
preferences
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
- add types to handlers in the Getting Started section to align with the
examples in the Concepts section
- prefix unused arguments with `_` as suggested by official VSCode
plugin linting.
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
One can now inline the `imports` and `scopes` from the import map directly into deno.json.
For new projects, `import_map.json` is not generated anymore.
Co-authored-by: Luca Casonato <hello@lcas.dev>
This will allow us to add various caches and similar around the esbuild
builder easily in follow up PRs.
It also makes doing an AOT build-step + load assets from disk much
simpler.
close#1187
## points
- use `<link rel="modulepreload">` tag and `Link: rel="modulepreload"`
header to preload dependencies
- No preloading at all for pages that don't use JavaScript at all.
- Information about preloading is delivered only when the JS file has
already been built. If the JS file hasn't finished building, it will
respond without preload information instead of waiting for the build and
then returning the HTML.
## performance comparison
I've deployed this branch to https://fresh-module-preload.deno.dev/ so
you can try it out and see how it behaves.
When I accessed [fresh.deno.dev](https://fresh.deno.dev/) and
[fresh-module-preload.deno.dev](https://fresh-module-preload.deno.dev/)
20 times each and measured the DOMContentLoaded time, it was 24% faster
(157.3ms -> 118.95ms) in my environment (Nagano City, Japan).
<details>
<summary>Actual measured data</summary>
(Don't forget to check `Disable Cache` in devtools)
| afeter (ms) | before (ms)
-- | -- | --
0 | 180 | 152
1 | 82 | 144
2 | 78 | 186
3 | 156 | 196
4 | 88 | 211
5 | 85 | 123
6 | 162 | 209
7 | 154 | 110
8 | 86 | 175
9 | 135 | 109
10 | 183 | 117
11 | 115 | 159
12 | 99 | 173
13 | 83 | 131
14 | 82 | 142
15 | 135 | 160
16 | 120 | 125
17 | 148 | 152
18 | 118 | 229
19 | 90 | 143
average | 118.95 | 157.3
</details>
## screen shots


---------
Co-authored-by: Luca Casonato <hello@lcas.dev>
This commit adds support for passing signals to islands in component
props. This is useful for passing around mutable state between islands.
The signal's value needs to be serializable for this to work.
This commit adds support for an advanced (de)serializer that is used
for page state (island props and plugin state). This new serializer
supports maintaining references (thus supporting circular objects,
and multi-referenced objects).
This is a pre-requisite for allowing to pass signals, JSX, Uint8Arrays,
Date, and many other "advanced" values.
We now add a default HEAD handler to the server, rather than special
casing HEAD requests elsewhere. Static files now get their own optimized
HEAD handler that does not read the file contents.
This could happen if the runtime/utils.ts coe was loaded
prior to server/constants.ts, because they had some shared state on
`globalThis`.
I have mitigated this by not relying on global state anymore.
Fixes#1191
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
I cut out the function that gets an hundler from fresh.
The purpose is to prepare you to create tests for your application.
The introduction of this feature does not affect fresh.
Example:
```typescript main_test.ts
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />
import { createHandler } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
import { superdeno } from "https://deno.land/x/superdeno/mod.ts";
import { assertEquals } from "https://deno.land/std@0.148.0/testing/asserts.ts";
import {
type RequestHandlerLike,
} from "https://deno.land/x/superdeno/src/types.ts";
import {
Document,
DOMParser,
} from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
Deno.test("HTTP assert test.", async (t) => {
await t.step("#1 GET /", async () => {
const handler = await createHandler(manifest) as RequestHandlerLike;
await superdeno(handler)
.get("/")
.expect(200);
});
await t.step("#2 GET /Foo", async () => {
const server = await createHandler(manifest) as RequestHandlerLike;
const r = await superdeno(server)
.get("/Foo")
.expect(200);
const document: Document = new DOMParser().parseFromString(
r.text,
"text/html",
)!;
assertEquals(document.querySelector("div")?.innerText, "Hello Foo");
});
await t.step("#3 GET /Foo/Bar", async () => {
const server = await createHandler(manifest) as RequestHandlerLike;
await superdeno(server)
.get("/Foo/Bar")
.expect(404);
});
});
```
```sh
$ deno test -A main_test.ts
Check file:///usr/src/app/my-project/main_test.ts
running 1 test from ./main_test.ts
HTTP assert test. ...
#1 GET / ... ok (53ms)
#2 GET /Foo ... ok (50ms)
#3 GET /Foo/Bar ... ok (45ms)
HTTP assert test. ... ok (154ms)
ok | 1 passed (3 steps) | 0 failed (300ms)
```
This was discussed in a separate pull request, but prepared in a
separate branch based on @lucacasonato suggestion.
[Add a function to get a server class
instance.](https://github.com/denoland/fresh/pull/552)
Thenk you.
I was caught out by trying to pass `Infinity` as a prop to an island,
which is a valid IEEE 754 float, but bizarrely JSON serializes to
`null`.
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Fixes#1015
This scenario can happen when a user has a proxy sitting in front of
Fresh, that does TLS termination, while Fresh is running on plain text
HTTP.
---------
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>