Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/server-function-call-observers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/web": patch
---

Adopt `@dom-expressions/runtime` 0.50.0-next.44 and expose server-function call observers.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@changesets/cli": "^2.25.2",
"@dom-expressions/babel-plugin-jsx": "0.50.0-next.43",
"@dom-expressions/hyperscript": "0.50.0-next.43",
"@dom-expressions/runtime": "0.50.0-next.43",
"@dom-expressions/runtime": "0.50.0-next.44",
"@dom-expressions/tagged-jsx": "0.50.0-next.43",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import {
createServerReference,
getServerFunctionMetadata,
isServerFunction,
observeServerFunctionCalls,
withMeta
} from "@solidjs/web/server-functions/client";
import type { PrepareRequestHook } from "@solidjs/web/server-functions/client";
import type { PrepareRequestHook, ServerFunctionCall } from "@solidjs/web/server-functions/client";

const RequestContext = Symbol.for("solid.RequestContext");

Expand All @@ -48,9 +49,11 @@ afterAll(() => {
// handler — a full round trip through both published bundles.
function connectTransport() {
const original = globalThis.fetch;
globalThis.fetch = ((url: string, init?: RequestInit) =>
globalThis.fetch = ((input: RequestInfo | URL, init?: RequestInit) =>
handleServerFunctionRequest(
new Request(new URL(url, "http://localhost"), init)
input instanceof Request
? input
: new Request(new URL(input.toString(), "http://localhost"), init)
)) as typeof fetch;
return () => {
globalThis.fetch = original;
Expand Down Expand Up @@ -164,6 +167,28 @@ describe("server-function extension surface (built bundles)", () => {
}
});

it("observes calls through the client bridge", async () => {
registerServerFunction("ext-observe-0", async (value: number) => value * 2);
const calls: ServerFunctionCall[] = [];
const stop = observeServerFunctionCalls(call => calls.push(call));
const restore = connectTransport();
try {
expect(await createServerReference("ext-observe-0")(21)).toBe(42);
expect(calls.map(call => call.type)).toEqual(["request", "response"]);
expect(calls[0]).toMatchObject({
id: "ext-observe-0",
instance: expect.any(String)
});
expect(calls[1]).toMatchObject({
id: "ext-observe-0",
instance: calls[0].instance
});
} finally {
stop();
restore();
}
});

it("references expose id and drop the legacy escape hatches", () => {
const ref = createServerReference("ext-contract-0");
expect(ref.id).toBe("ext-contract-0");
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading