From 63ac1e6362a14c99b44c4c3a4362c663ed190e49 Mon Sep 17 00:00:00 2001 From: Reed von Redwitz Date: Thu, 26 Oct 2023 22:26:36 +0200 Subject: [PATCH] feat(server): add isPartial to context types (#1977) --- src/server/compose.ts | 9 +- src/server/context.ts | 4 +- src/server/render.ts | 1 + src/server/router.ts | 20 +- src/server/types.ts | 3 + tests/fixture_partials/fresh.gen.ts | 230 +++++++++--------- .../routes/isPartial/_middleware.ts | 18 ++ .../routes/isPartial/async.tsx | 24 ++ .../routes/isPartial/handler.tsx | 32 +++ .../routes/isPartial/index.tsx | 28 +++ .../routes/isPartial/injected.tsx | 10 + tests/partials_test.ts | 74 ++++++ tests/server_components_test.ts | 1 + 13 files changed, 333 insertions(+), 121 deletions(-) create mode 100644 tests/fixture_partials/routes/isPartial/_middleware.ts create mode 100644 tests/fixture_partials/routes/isPartial/async.tsx create mode 100644 tests/fixture_partials/routes/isPartial/handler.tsx create mode 100644 tests/fixture_partials/routes/isPartial/index.tsx create mode 100644 tests/fixture_partials/routes/isPartial/injected.tsx diff --git a/src/server/compose.ts b/src/server/compose.ts index 226dce3b..3471f9fc 100644 --- a/src/server/compose.ts +++ b/src/server/compose.ts @@ -1,4 +1,4 @@ -import { ErrorHandler, FinalHandler, InternalRoute } from "./router.ts"; +import { ErrorHandler, FinalHandler, RouteResult } from "./router.ts"; import { BaseRoute, MiddlewareHandlerContext, @@ -55,10 +55,7 @@ export function composeMiddlewares( errorHandler: ErrorHandler, paramsAndRoute: ( url: string, - ) => { - route: InternalRoute | undefined; - params: Record; - }, + ) => RouteResult, ) { return ( req: Request, @@ -103,6 +100,7 @@ export function composeMiddlewares( }, destination: "route", params: paramsAndRouteResult.params, + isPartial: paramsAndRouteResult.isPartial, }; for (const { module } of mws) { @@ -124,6 +122,7 @@ export function composeMiddlewares( set state(v) { state = v; }, + isPartial: paramsAndRouteResult.isPartial, }; const { destination, handler } = inner( req, diff --git a/src/server/context.ts b/src/server/context.ts index cfcb5c9d..72b4b1c0 100644 --- a/src/server/context.ts +++ b/src/server/context.ts @@ -163,7 +163,9 @@ export class ServerContext { return response; } else if (url.pathname === DEV_CLIENT_URL) { - return bundleAssetRoute(req, connInfo, { path: "client.js" }); + return bundleAssetRoute(req, { ...connInfo, isPartial: false }, { + path: "client.js", + }); } } diff --git a/src/server/render.ts b/src/server/render.ts index 63729809..342b1758 100644 --- a/src/server/render.ts +++ b/src/server/render.ts @@ -184,6 +184,7 @@ export async function render( params: opts.params as Record, state: opts.state ?? {}, data: opts.data, + isPartial: opts.context.isPartial, }; // Prepare render order diff --git a/src/server/router.ts b/src/server/router.ts index 76bb3698..d35ea44c 100644 --- a/src/server/router.ts +++ b/src/server/router.ts @@ -1,6 +1,9 @@ +import { PARTIAL_SEARCH_PARAM } from "$fresh/src/constants.ts"; import { BaseRoute, ErrorHandlerContext, ServeHandlerInfo } from "./types.ts"; -type HandlerContext = T & ServeHandlerInfo; +type HandlerContext = T & ServeHandlerInfo & { + isPartial: boolean; +}; export type Handler = ( req: Request, @@ -136,9 +139,10 @@ function processRoutes( } } -interface RouteResult { +export interface RouteResult { route: InternalRoute | undefined; params: Record; + isPartial: boolean; } export function getParamsAndRoute( @@ -158,7 +162,8 @@ export function getParamsAndRoute( const statics = new Map>(); return (url: string) => { - const pathname = new URL(url).pathname; + const urlObject = new URL(url); + const pathname = urlObject.pathname; const cached = statics.get(pathname); if (cached !== undefined) { return cached; @@ -174,7 +179,7 @@ export function getParamsAndRoute( if (typeof route.pattern === "string") { if (route.pattern === pathname) { processedRoutes[i] = null; - const res = { route: route, params: {} }; + const res = { route: route, params: {}, isPartial: false }; statics.set(route.pattern, res); return res; } @@ -195,12 +200,17 @@ export function getParamsAndRoute( groups[key] = decodeURIComponent(value); } } - return { route: route, params: groups }; + return { + route: route, + params: groups, + isPartial: urlObject.searchParams.has(PARTIAL_SEARCH_PARAM), + }; } } return { route: undefined, params: {}, + isPartial: false, }; }; } diff --git a/src/server/types.ts b/src/server/types.ts index e54019e2..56fb78fa 100644 --- a/src/server/types.ts +++ b/src/server/types.ts @@ -207,6 +207,7 @@ export type RouteContext> = { params: Record; state: S; data: T; + isPartial: boolean; }; export interface RouteConfig { @@ -268,6 +269,7 @@ export interface HandlerContext< ) => Response | Promise; renderNotFound: (data?: NotFoundData) => Response | Promise; state: State; + isPartial: boolean; } // deno-lint-ignore no-explicit-any @@ -489,6 +491,7 @@ export interface MiddlewareHandlerContext> state: State; destination: router.DestinationKind; params: Record; + isPartial: boolean; } export interface MiddlewareRoute { diff --git a/tests/fixture_partials/fresh.gen.ts b/tests/fixture_partials/fresh.gen.ts index 263af675..efd54452 100644 --- a/tests/fixture_partials/fresh.gen.ts +++ b/tests/fixture_partials/fresh.gen.ts @@ -50,61 +50,66 @@ import * as $44 from "./routes/head_merge/index.tsx"; import * as $45 from "./routes/head_merge/injected.tsx"; import * as $46 from "./routes/head_merge/update.tsx"; import * as $47 from "./routes/index.tsx"; -import * as $48 from "./routes/island_instance/index.tsx"; -import * as $49 from "./routes/island_instance/injected.tsx"; -import * as $50 from "./routes/island_instance/partial.tsx"; -import * as $51 from "./routes/island_instance/partial_remove.tsx"; -import * as $52 from "./routes/island_instance/partial_replace.tsx"; -import * as $53 from "./routes/island_instance_multiple/index.tsx"; -import * as $54 from "./routes/island_instance_multiple/injected.tsx"; -import * as $55 from "./routes/island_instance_multiple/partial.tsx"; -import * as $56 from "./routes/island_instance_multiple/partial_both.tsx"; -import * as $57 from "./routes/island_instance_nested/index.tsx"; -import * as $58 from "./routes/island_instance_nested/injected.tsx"; -import * as $59 from "./routes/island_instance_nested/partial.tsx"; -import * as $60 from "./routes/island_instance_nested/replace.tsx"; -import * as $61 from "./routes/island_props/index.tsx"; -import * as $62 from "./routes/island_props/injected.tsx"; -import * as $63 from "./routes/island_props/partial.tsx"; -import * as $64 from "./routes/island_props_signals/index.tsx"; -import * as $65 from "./routes/island_props_signals/injected.tsx"; -import * as $66 from "./routes/island_props_signals/partial.tsx"; -import * as $67 from "./routes/keys/index.tsx"; -import * as $68 from "./routes/keys/injected.tsx"; -import * as $69 from "./routes/keys/swap.tsx"; -import * as $70 from "./routes/keys_components/index.tsx"; -import * as $71 from "./routes/keys_components/injected.tsx"; -import * as $72 from "./routes/keys_components/swap.tsx"; -import * as $73 from "./routes/keys_confusion/index.tsx"; -import * as $74 from "./routes/keys_dom/index.tsx"; -import * as $75 from "./routes/keys_dom/injected.tsx"; -import * as $76 from "./routes/keys_dom/swap.tsx"; -import * as $77 from "./routes/keys_outside/index.tsx"; -import * as $78 from "./routes/loading/index.tsx"; -import * as $79 from "./routes/loading/injected.tsx"; -import * as $80 from "./routes/loading/update.tsx"; -import * as $81 from "./routes/missing_partial/index.tsx"; -import * as $82 from "./routes/missing_partial/injected.tsx"; -import * as $83 from "./routes/missing_partial/update.tsx"; -import * as $84 from "./routes/mode/append.tsx"; -import * as $85 from "./routes/mode/index.tsx"; -import * as $86 from "./routes/mode/injected.tsx"; -import * as $87 from "./routes/mode/prepend.tsx"; -import * as $88 from "./routes/mode/replace.tsx"; -import * as $89 from "./routes/nested/index.tsx"; -import * as $90 from "./routes/nested/inner.tsx"; -import * as $91 from "./routes/nested/outer.tsx"; -import * as $92 from "./routes/no_islands/index.tsx"; -import * as $93 from "./routes/no_islands/injected.tsx"; -import * as $94 from "./routes/no_islands/update.tsx"; -import * as $95 from "./routes/no_partial_response/index.tsx"; -import * as $96 from "./routes/no_partial_response/injected.tsx"; -import * as $97 from "./routes/no_partial_response/update.tsx"; -import * as $98 from "./routes/partial_slot_inside_island.tsx"; -import * as $99 from "./routes/relative_link/index.tsx"; -import * as $100 from "./routes/scroll_restoration/index.tsx"; -import * as $101 from "./routes/scroll_restoration/injected.tsx"; -import * as $102 from "./routes/scroll_restoration/update.tsx"; +import * as $48 from "./routes/isPartial/_middleware.ts"; +import * as $49 from "./routes/isPartial/async.tsx"; +import * as $50 from "./routes/isPartial/handler.tsx"; +import * as $51 from "./routes/isPartial/index.tsx"; +import * as $52 from "./routes/isPartial/injected.tsx"; +import * as $53 from "./routes/island_instance/index.tsx"; +import * as $54 from "./routes/island_instance/injected.tsx"; +import * as $55 from "./routes/island_instance/partial.tsx"; +import * as $56 from "./routes/island_instance/partial_remove.tsx"; +import * as $57 from "./routes/island_instance/partial_replace.tsx"; +import * as $58 from "./routes/island_instance_multiple/index.tsx"; +import * as $59 from "./routes/island_instance_multiple/injected.tsx"; +import * as $60 from "./routes/island_instance_multiple/partial.tsx"; +import * as $61 from "./routes/island_instance_multiple/partial_both.tsx"; +import * as $62 from "./routes/island_instance_nested/index.tsx"; +import * as $63 from "./routes/island_instance_nested/injected.tsx"; +import * as $64 from "./routes/island_instance_nested/partial.tsx"; +import * as $65 from "./routes/island_instance_nested/replace.tsx"; +import * as $66 from "./routes/island_props/index.tsx"; +import * as $67 from "./routes/island_props/injected.tsx"; +import * as $68 from "./routes/island_props/partial.tsx"; +import * as $69 from "./routes/island_props_signals/index.tsx"; +import * as $70 from "./routes/island_props_signals/injected.tsx"; +import * as $71 from "./routes/island_props_signals/partial.tsx"; +import * as $72 from "./routes/keys/index.tsx"; +import * as $73 from "./routes/keys/injected.tsx"; +import * as $74 from "./routes/keys/swap.tsx"; +import * as $75 from "./routes/keys_components/index.tsx"; +import * as $76 from "./routes/keys_components/injected.tsx"; +import * as $77 from "./routes/keys_components/swap.tsx"; +import * as $78 from "./routes/keys_confusion/index.tsx"; +import * as $79 from "./routes/keys_dom/index.tsx"; +import * as $80 from "./routes/keys_dom/injected.tsx"; +import * as $81 from "./routes/keys_dom/swap.tsx"; +import * as $82 from "./routes/keys_outside/index.tsx"; +import * as $83 from "./routes/loading/index.tsx"; +import * as $84 from "./routes/loading/injected.tsx"; +import * as $85 from "./routes/loading/update.tsx"; +import * as $86 from "./routes/missing_partial/index.tsx"; +import * as $87 from "./routes/missing_partial/injected.tsx"; +import * as $88 from "./routes/missing_partial/update.tsx"; +import * as $89 from "./routes/mode/append.tsx"; +import * as $90 from "./routes/mode/index.tsx"; +import * as $91 from "./routes/mode/injected.tsx"; +import * as $92 from "./routes/mode/prepend.tsx"; +import * as $93 from "./routes/mode/replace.tsx"; +import * as $94 from "./routes/nested/index.tsx"; +import * as $95 from "./routes/nested/inner.tsx"; +import * as $96 from "./routes/nested/outer.tsx"; +import * as $97 from "./routes/no_islands/index.tsx"; +import * as $98 from "./routes/no_islands/injected.tsx"; +import * as $99 from "./routes/no_islands/update.tsx"; +import * as $100 from "./routes/no_partial_response/index.tsx"; +import * as $101 from "./routes/no_partial_response/injected.tsx"; +import * as $102 from "./routes/no_partial_response/update.tsx"; +import * as $103 from "./routes/partial_slot_inside_island.tsx"; +import * as $104 from "./routes/relative_link/index.tsx"; +import * as $105 from "./routes/scroll_restoration/index.tsx"; +import * as $106 from "./routes/scroll_restoration/injected.tsx"; +import * as $107 from "./routes/scroll_restoration/update.tsx"; import * as $$0 from "./islands/Counter.tsx"; import * as $$1 from "./islands/CounterA.tsx"; import * as $$2 from "./islands/CounterB.tsx"; @@ -171,61 +176,66 @@ const manifest = { "./routes/head_merge/injected.tsx": $45, "./routes/head_merge/update.tsx": $46, "./routes/index.tsx": $47, - "./routes/island_instance/index.tsx": $48, - "./routes/island_instance/injected.tsx": $49, - "./routes/island_instance/partial.tsx": $50, - "./routes/island_instance/partial_remove.tsx": $51, - "./routes/island_instance/partial_replace.tsx": $52, - "./routes/island_instance_multiple/index.tsx": $53, - "./routes/island_instance_multiple/injected.tsx": $54, - "./routes/island_instance_multiple/partial.tsx": $55, - "./routes/island_instance_multiple/partial_both.tsx": $56, - "./routes/island_instance_nested/index.tsx": $57, - "./routes/island_instance_nested/injected.tsx": $58, - "./routes/island_instance_nested/partial.tsx": $59, - "./routes/island_instance_nested/replace.tsx": $60, - "./routes/island_props/index.tsx": $61, - "./routes/island_props/injected.tsx": $62, - "./routes/island_props/partial.tsx": $63, - "./routes/island_props_signals/index.tsx": $64, - "./routes/island_props_signals/injected.tsx": $65, - "./routes/island_props_signals/partial.tsx": $66, - "./routes/keys/index.tsx": $67, - "./routes/keys/injected.tsx": $68, - "./routes/keys/swap.tsx": $69, - "./routes/keys_components/index.tsx": $70, - "./routes/keys_components/injected.tsx": $71, - "./routes/keys_components/swap.tsx": $72, - "./routes/keys_confusion/index.tsx": $73, - "./routes/keys_dom/index.tsx": $74, - "./routes/keys_dom/injected.tsx": $75, - "./routes/keys_dom/swap.tsx": $76, - "./routes/keys_outside/index.tsx": $77, - "./routes/loading/index.tsx": $78, - "./routes/loading/injected.tsx": $79, - "./routes/loading/update.tsx": $80, - "./routes/missing_partial/index.tsx": $81, - "./routes/missing_partial/injected.tsx": $82, - "./routes/missing_partial/update.tsx": $83, - "./routes/mode/append.tsx": $84, - "./routes/mode/index.tsx": $85, - "./routes/mode/injected.tsx": $86, - "./routes/mode/prepend.tsx": $87, - "./routes/mode/replace.tsx": $88, - "./routes/nested/index.tsx": $89, - "./routes/nested/inner.tsx": $90, - "./routes/nested/outer.tsx": $91, - "./routes/no_islands/index.tsx": $92, - "./routes/no_islands/injected.tsx": $93, - "./routes/no_islands/update.tsx": $94, - "./routes/no_partial_response/index.tsx": $95, - "./routes/no_partial_response/injected.tsx": $96, - "./routes/no_partial_response/update.tsx": $97, - "./routes/partial_slot_inside_island.tsx": $98, - "./routes/relative_link/index.tsx": $99, - "./routes/scroll_restoration/index.tsx": $100, - "./routes/scroll_restoration/injected.tsx": $101, - "./routes/scroll_restoration/update.tsx": $102, + "./routes/isPartial/_middleware.ts": $48, + "./routes/isPartial/async.tsx": $49, + "./routes/isPartial/handler.tsx": $50, + "./routes/isPartial/index.tsx": $51, + "./routes/isPartial/injected.tsx": $52, + "./routes/island_instance/index.tsx": $53, + "./routes/island_instance/injected.tsx": $54, + "./routes/island_instance/partial.tsx": $55, + "./routes/island_instance/partial_remove.tsx": $56, + "./routes/island_instance/partial_replace.tsx": $57, + "./routes/island_instance_multiple/index.tsx": $58, + "./routes/island_instance_multiple/injected.tsx": $59, + "./routes/island_instance_multiple/partial.tsx": $60, + "./routes/island_instance_multiple/partial_both.tsx": $61, + "./routes/island_instance_nested/index.tsx": $62, + "./routes/island_instance_nested/injected.tsx": $63, + "./routes/island_instance_nested/partial.tsx": $64, + "./routes/island_instance_nested/replace.tsx": $65, + "./routes/island_props/index.tsx": $66, + "./routes/island_props/injected.tsx": $67, + "./routes/island_props/partial.tsx": $68, + "./routes/island_props_signals/index.tsx": $69, + "./routes/island_props_signals/injected.tsx": $70, + "./routes/island_props_signals/partial.tsx": $71, + "./routes/keys/index.tsx": $72, + "./routes/keys/injected.tsx": $73, + "./routes/keys/swap.tsx": $74, + "./routes/keys_components/index.tsx": $75, + "./routes/keys_components/injected.tsx": $76, + "./routes/keys_components/swap.tsx": $77, + "./routes/keys_confusion/index.tsx": $78, + "./routes/keys_dom/index.tsx": $79, + "./routes/keys_dom/injected.tsx": $80, + "./routes/keys_dom/swap.tsx": $81, + "./routes/keys_outside/index.tsx": $82, + "./routes/loading/index.tsx": $83, + "./routes/loading/injected.tsx": $84, + "./routes/loading/update.tsx": $85, + "./routes/missing_partial/index.tsx": $86, + "./routes/missing_partial/injected.tsx": $87, + "./routes/missing_partial/update.tsx": $88, + "./routes/mode/append.tsx": $89, + "./routes/mode/index.tsx": $90, + "./routes/mode/injected.tsx": $91, + "./routes/mode/prepend.tsx": $92, + "./routes/mode/replace.tsx": $93, + "./routes/nested/index.tsx": $94, + "./routes/nested/inner.tsx": $95, + "./routes/nested/outer.tsx": $96, + "./routes/no_islands/index.tsx": $97, + "./routes/no_islands/injected.tsx": $98, + "./routes/no_islands/update.tsx": $99, + "./routes/no_partial_response/index.tsx": $100, + "./routes/no_partial_response/injected.tsx": $101, + "./routes/no_partial_response/update.tsx": $102, + "./routes/partial_slot_inside_island.tsx": $103, + "./routes/relative_link/index.tsx": $104, + "./routes/scroll_restoration/index.tsx": $105, + "./routes/scroll_restoration/injected.tsx": $106, + "./routes/scroll_restoration/update.tsx": $107, }, islands: { "./islands/Counter.tsx": $$0, diff --git a/tests/fixture_partials/routes/isPartial/_middleware.ts b/tests/fixture_partials/routes/isPartial/_middleware.ts new file mode 100644 index 00000000..3e8a9413 --- /dev/null +++ b/tests/fixture_partials/routes/isPartial/_middleware.ts @@ -0,0 +1,18 @@ +import { MiddlewareHandlerContext } from "$fresh/server.ts"; + +export type IsPartialInContextState = { + setFromMiddleware: boolean; + notSetFromMiddleware: boolean; +}; + +export async function handler( + _req: Request, + ctx: MiddlewareHandlerContext, +) { + if (ctx.isPartial) { + ctx.state.setFromMiddleware = true; + } else { + ctx.state.notSetFromMiddleware = true; + } + return await ctx.next(); +} diff --git a/tests/fixture_partials/routes/isPartial/async.tsx b/tests/fixture_partials/routes/isPartial/async.tsx new file mode 100644 index 00000000..4285c284 --- /dev/null +++ b/tests/fixture_partials/routes/isPartial/async.tsx @@ -0,0 +1,24 @@ +import { defineRoute, RouteConfig } from "$fresh/server.ts"; +import { IsPartialInContextState } from "./_middleware.ts"; +import { Partial } from "$fresh/runtime.ts"; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export default defineRoute((req, ctx) => { + const result = { + isPartial: ctx.isPartial, + setFromMiddleware: ctx.state.setFromMiddleware, + notSetFromMiddleware: ctx.state.notSetFromMiddleware, + }; + if (ctx.isPartial) { + return ( + +
{JSON.stringify(result, null, 2)}
+
+ ); + } + return
{JSON.stringify(result, null, 2)}
; +}); diff --git a/tests/fixture_partials/routes/isPartial/handler.tsx b/tests/fixture_partials/routes/isPartial/handler.tsx new file mode 100644 index 00000000..12c33a34 --- /dev/null +++ b/tests/fixture_partials/routes/isPartial/handler.tsx @@ -0,0 +1,32 @@ +import { Handlers, PageProps, RouteConfig } from "$fresh/server.ts"; +import { IsPartialInContextState } from "./_middleware.ts"; +import { Partial } from "$fresh/runtime.ts"; + +export const config: RouteConfig = { + skipAppWrapper: true, + skipInheritedLayouts: true, +}; + +export const handler: Handlers = { + GET(_req, ctx) { + return ctx.render(ctx.isPartial); + }, +}; + +export default function Home( + props: PageProps, +) { + const result = { + isPartial: props.data, + setFromMiddleware: props.state.setFromMiddleware, + notSetFromMiddleware: props.state.notSetFromMiddleware, + }; + if (props.data) { + return ( + +
{JSON.stringify(result, null, 2)}
+
+ ); + } + return
{JSON.stringify(result, null, 2)}
; +} diff --git a/tests/fixture_partials/routes/isPartial/index.tsx b/tests/fixture_partials/routes/isPartial/index.tsx new file mode 100644 index 00000000..bb63df96 --- /dev/null +++ b/tests/fixture_partials/routes/isPartial/index.tsx @@ -0,0 +1,28 @@ +import { Partial } from "$fresh/runtime.ts"; + +export default function SlotDemo() { + return ( +
+
+ +

Default content

+
+
+ + handler update + +
+ + async update + +
+ ); +} diff --git a/tests/fixture_partials/routes/isPartial/injected.tsx b/tests/fixture_partials/routes/isPartial/injected.tsx new file mode 100644 index 00000000..4908eeeb --- /dev/null +++ b/tests/fixture_partials/routes/isPartial/injected.tsx @@ -0,0 +1,10 @@ +import { defineRoute } from "$fresh/src/server/defines.ts"; + +export default defineRoute(() => { + return new Response("", { + status: 302, + headers: { + Location: "/isPartial", + }, + }); +}); diff --git a/tests/partials_test.ts b/tests/partials_test.ts index dd435d9c..8a88aaf8 100644 --- a/tests/partials_test.ts +++ b/tests/partials_test.ts @@ -1423,3 +1423,77 @@ Deno.test("errors on duplicate partial name", async () => { }, ); }); + +Deno.test("normal visit to handler page", async () => { + await withFakeServe( + "./tests/fixture_partials/main.ts", + async (server) => { + const html = await server.getHtml("/isPartial/handler"); + assertEquals(JSON.parse(html.querySelector("pre")!.textContent!), { + isPartial: false, + notSetFromMiddleware: true, + }); + }, + ); +}); + +Deno.test("normal visit to async page", async () => { + await withFakeServe( + "./tests/fixture_partials/main.ts", + async (server) => { + const html = await server.getHtml("/isPartial/async"); + assertEquals(JSON.parse(html.querySelector("pre")!.textContent!), { + isPartial: false, + notSetFromMiddleware: true, + }); + }, + ); +}); + +Deno.test("partials visit to handler page", async () => { + await withPageName( + "./tests/fixture_partials/main.ts", + async (page, address) => { + await page.goto(`${address}/isPartial`); + await page.waitForSelector(".output"); + + const href = await page.$eval(".handler-update-link", (el) => el.href); + await page.click(".handler-update-link"); + await page.waitForSelector("pre"); + + assertEquals(href, await page.url()); + await assertNoPageComments(page); + const result = await page.$eval("pre", (el) => { + return el.textContent; + }); + assertEquals(JSON.parse(result), { + isPartial: true, + setFromMiddleware: true, + }); + }, + ); +}); + +Deno.test("partials visit to async page", async () => { + await withPageName( + "./tests/fixture_partials/main.ts", + async (page, address) => { + await page.goto(`${address}/isPartial`); + await page.waitForSelector(".output"); + + const href = await page.$eval(".async-update-link", (el) => el.href); + await page.click(".async-update-link"); + await page.waitForSelector("pre"); + + assertEquals(href, await page.url()); + await assertNoPageComments(page); + const result = await page.$eval("pre", (el) => { + return el.textContent; + }); + assertEquals(JSON.parse(result), { + isPartial: true, + setFromMiddleware: true, + }); + }, + ); +}); diff --git a/tests/server_components_test.ts b/tests/server_components_test.ts index 69849710..95afeccb 100644 --- a/tests/server_components_test.ts +++ b/tests/server_components_test.ts @@ -93,6 +93,7 @@ Deno.test({ id: "foo", }, state: {}, + isPartial: false, }, ); },