From f2467229cc8a51162643477bfcb223cf42f69623 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Wed, 4 Oct 2023 12:35:29 +0200 Subject: [PATCH] fix: use consistent partial attribute naming (#1847) --- src/constants.ts | 5 +++-- src/runtime/entrypoints/main.ts | 5 +++-- tests/fixture_partials/islands/PartialTrigger.tsx | 4 ++-- tests/fixture_partials/routes/client_nav/_layout.tsx | 2 +- .../fixture_partials/routes/client_nav_opt_out/_layout.tsx | 2 +- tests/fixture_partials/routes/form/index.tsx | 2 +- tests/fixture_partials/routes/island_instance/index.tsx | 6 +++--- .../routes/island_instance_multiple/index.tsx | 4 ++-- .../routes/island_instance_nested/index.tsx | 4 ++-- tests/fixture_partials/routes/island_props/index.tsx | 2 +- .../fixture_partials/routes/island_props_signals/index.tsx | 2 +- tests/fixture_partials/routes/keys/index.tsx | 2 +- tests/fixture_partials/routes/keys_components/index.tsx | 2 +- tests/fixture_partials/routes/keys_dom/index.tsx | 2 +- tests/fixture_partials/routes/loading/index.tsx | 4 ++-- tests/fixture_partials/routes/missing_partial/index.tsx | 2 +- tests/fixture_partials/routes/mode/index.tsx | 6 +++--- tests/fixture_partials/routes/no_islands/index.tsx | 2 +- 18 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index b4ae8f60..69c52b5a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,7 @@ export const PARTIAL_SEARCH_PARAM = "fresh-partial"; -export const PARTIAL_ATTR = "fh-partial"; -export const LOADING_ATTR = "fh-loading"; +export const PARTIAL_ATTR = "f-partial"; +export const LOADING_ATTR = "f-loading"; +export const CLIENT_NAV_ATTR = "f-client-nav"; export const DATA_KEY_ATTR = "data-fresh-key"; export const enum PartialMode { diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts index b8281a4a..9ef4ead1 100644 --- a/src/runtime/entrypoints/main.ts +++ b/src/runtime/entrypoints/main.ts @@ -13,6 +13,7 @@ import { assetHashingHook } from "../utils.ts"; import { type SerializedState } from "../../server/rendering/fresh_tags.tsx"; import type { Signal } from "@preact/signals"; import { + CLIENT_NAV_ATTR, DATA_KEY_ATTR, LOADING_ATTR, PARTIAL_ATTR, @@ -748,11 +749,11 @@ document.addEventListener("click", async (e) => { // There are two cases to account for: // 1. Partial request // 2. Normal request (turbolink-style) - const settingEl = el.closest("[fresh-client-nav]"); + const settingEl = el.closest(`[${CLIENT_NAV_ATTR}]`); if ( partial === null && ( settingEl === null || - settingEl.getAttribute("fresh-client-nav") !== "true" + settingEl.getAttribute(CLIENT_NAV_ATTR) !== "true" ) ) { return; diff --git a/tests/fixture_partials/islands/PartialTrigger.tsx b/tests/fixture_partials/islands/PartialTrigger.tsx index c8989947..1ab50a25 100644 --- a/tests/fixture_partials/islands/PartialTrigger.tsx +++ b/tests/fixture_partials/islands/PartialTrigger.tsx @@ -14,8 +14,8 @@ export default function PartialTrigger( {props.children} diff --git a/tests/fixture_partials/routes/client_nav/_layout.tsx b/tests/fixture_partials/routes/client_nav/_layout.tsx index 0390b3f7..714741f4 100644 --- a/tests/fixture_partials/routes/client_nav/_layout.tsx +++ b/tests/fixture_partials/routes/client_nav/_layout.tsx @@ -10,7 +10,7 @@ export default function AppLayout({ Component }: AppProps) { fresh title - + diff --git a/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx b/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx index 56ac8878..c733ceb4 100644 --- a/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx +++ b/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx @@ -10,7 +10,7 @@ export default function AppLayout({ Component }: AppProps) { fresh title - + diff --git a/tests/fixture_partials/routes/form/index.tsx b/tests/fixture_partials/routes/form/index.tsx index 77cd87b9..7e911445 100644 --- a/tests/fixture_partials/routes/form/index.tsx +++ b/tests/fixture_partials/routes/form/index.tsx @@ -3,7 +3,7 @@ import { Partial } from "$fresh/runtime.ts"; export default function SlotDemo() { return (
-
+

Default content

diff --git a/tests/fixture_partials/routes/island_instance/index.tsx b/tests/fixture_partials/routes/island_instance/index.tsx index bb41caa4..7b40fba0 100644 --- a/tests/fixture_partials/routes/island_instance/index.tsx +++ b/tests/fixture_partials/routes/island_instance/index.tsx @@ -15,7 +15,7 @@ export default function SlotDemo() { Update @@ -24,7 +24,7 @@ export default function SlotDemo() { Remove @@ -33,7 +33,7 @@ export default function SlotDemo() { Replace diff --git a/tests/fixture_partials/routes/island_instance_multiple/index.tsx b/tests/fixture_partials/routes/island_instance_multiple/index.tsx index 30ca9231..38315fe9 100644 --- a/tests/fixture_partials/routes/island_instance_multiple/index.tsx +++ b/tests/fixture_partials/routes/island_instance_multiple/index.tsx @@ -26,7 +26,7 @@ export default function SlotDemo() { update second @@ -35,7 +35,7 @@ export default function SlotDemo() { update both diff --git a/tests/fixture_partials/routes/island_instance_nested/index.tsx b/tests/fixture_partials/routes/island_instance_nested/index.tsx index 8b8c968f..4a3d3c47 100644 --- a/tests/fixture_partials/routes/island_instance_nested/index.tsx +++ b/tests/fixture_partials/routes/island_instance_nested/index.tsx @@ -24,7 +24,7 @@ export default function SlotDemo() { update @@ -33,7 +33,7 @@ export default function SlotDemo() { replace diff --git a/tests/fixture_partials/routes/island_props/index.tsx b/tests/fixture_partials/routes/island_props/index.tsx index 53069258..80d2da33 100644 --- a/tests/fixture_partials/routes/island_props/index.tsx +++ b/tests/fixture_partials/routes/island_props/index.tsx @@ -21,7 +21,7 @@ export default function PropsDemo() { Update diff --git a/tests/fixture_partials/routes/island_props_signals/index.tsx b/tests/fixture_partials/routes/island_props_signals/index.tsx index 4b0848b5..a6fff773 100644 --- a/tests/fixture_partials/routes/island_props_signals/index.tsx +++ b/tests/fixture_partials/routes/island_props_signals/index.tsx @@ -20,7 +20,7 @@ export default function PropsDemo() { Update diff --git a/tests/fixture_partials/routes/keys/index.tsx b/tests/fixture_partials/routes/keys/index.tsx index c5609eff..85e4d6d3 100644 --- a/tests/fixture_partials/routes/keys/index.tsx +++ b/tests/fixture_partials/routes/keys/index.tsx @@ -19,7 +19,7 @@ export default function SlotDemo() { swap diff --git a/tests/fixture_partials/routes/keys_components/index.tsx b/tests/fixture_partials/routes/keys_components/index.tsx index 372f676e..af0a7c76 100644 --- a/tests/fixture_partials/routes/keys_components/index.tsx +++ b/tests/fixture_partials/routes/keys_components/index.tsx @@ -26,7 +26,7 @@ export default function SlotDemo() { swap diff --git a/tests/fixture_partials/routes/keys_dom/index.tsx b/tests/fixture_partials/routes/keys_dom/index.tsx index 9369494b..5cb5b2bf 100644 --- a/tests/fixture_partials/routes/keys_dom/index.tsx +++ b/tests/fixture_partials/routes/keys_dom/index.tsx @@ -27,7 +27,7 @@ export default function SlotDemo() { swap diff --git a/tests/fixture_partials/routes/loading/index.tsx b/tests/fixture_partials/routes/loading/index.tsx index e9336c7d..b5ea8afe 100644 --- a/tests/fixture_partials/routes/loading/index.tsx +++ b/tests/fixture_partials/routes/loading/index.tsx @@ -17,8 +17,8 @@ export default function SlotDemo() { update diff --git a/tests/fixture_partials/routes/missing_partial/index.tsx b/tests/fixture_partials/routes/missing_partial/index.tsx index 307f4542..beed883d 100644 --- a/tests/fixture_partials/routes/missing_partial/index.tsx +++ b/tests/fixture_partials/routes/missing_partial/index.tsx @@ -15,7 +15,7 @@ export default function WarnDemo() { update diff --git a/tests/fixture_partials/routes/mode/index.tsx b/tests/fixture_partials/routes/mode/index.tsx index a4d38007..951ce9a7 100644 --- a/tests/fixture_partials/routes/mode/index.tsx +++ b/tests/fixture_partials/routes/mode/index.tsx @@ -15,7 +15,7 @@ export default function ModeDemo() { replace @@ -24,7 +24,7 @@ export default function ModeDemo() { append @@ -33,7 +33,7 @@ export default function ModeDemo() { prepend diff --git a/tests/fixture_partials/routes/no_islands/index.tsx b/tests/fixture_partials/routes/no_islands/index.tsx index 7dfb196e..05832034 100644 --- a/tests/fixture_partials/routes/no_islands/index.tsx +++ b/tests/fixture_partials/routes/no_islands/index.tsx @@ -11,7 +11,7 @@ export default function SlotDemo() { update