From 41afb84057f606b0e7f9a73c1e40487068e43948 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 2 Aug 2023 14:42:01 -0400 Subject: [PATCH] Persistent DOM in ViewTransitions (#7861) * First pass at transition:persist * Persistent islands * Changeset * Updated compiler * Use official release * Upgrade again * Refactor to allow head content to persist untouched * >= * Specify the types for "astro:persist" * Automatically persist links * Use reference for array * Upgrade to latest compiler version * Explain the feature * Update .changeset/empty-experts-unite.md Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * Update .changeset/empty-experts-unite.md Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> * Update .changeset/empty-experts-unite.md Co-authored-by: Sarah Rainsberger * Update .changeset/empty-experts-unite.md Co-authored-by: Sarah Rainsberger --------- Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> Co-authored-by: Sarah Rainsberger --- .changeset/empty-experts-unite.md | 27 ++++++++ .../astro/components/ViewTransitions.astro | 67 ++++++++++++++++--- .../view-transitions/astro.config.mjs | 7 ++ .../fixtures/view-transitions/package.json | 5 +- .../src/components/Island.css | 11 +++ .../src/components/Island.jsx | 19 ++++++ .../src/components/Video.astro | 3 + .../src/pages/island-one.astro | 9 +++ .../src/pages/island-two.astro | 9 +++ .../src/pages/video-one.astro | 17 +++++ .../src/pages/video-two.astro | 14 ++++ packages/astro/e2e/view-transitions.test.js | 36 ++++++++++ packages/astro/package.json | 2 +- packages/astro/src/@types/astro.ts | 1 + packages/astro/src/core/compile/compile.ts | 1 + .../astro/src/runtime/server/hydration.ts | 8 +++ .../astro/src/runtime/server/transition.ts | 3 +- pnpm-lock.yaml | 25 ++++--- 18 files changed, 243 insertions(+), 21 deletions(-) create mode 100644 .changeset/empty-experts-unite.md create mode 100644 packages/astro/e2e/fixtures/view-transitions/src/components/Island.css create mode 100644 packages/astro/e2e/fixtures/view-transitions/src/components/Island.jsx create mode 100644 packages/astro/e2e/fixtures/view-transitions/src/components/Video.astro create mode 100644 packages/astro/e2e/fixtures/view-transitions/src/pages/island-one.astro create mode 100644 packages/astro/e2e/fixtures/view-transitions/src/pages/island-two.astro create mode 100644 packages/astro/e2e/fixtures/view-transitions/src/pages/video-one.astro create mode 100644 packages/astro/e2e/fixtures/view-transitions/src/pages/video-two.astro diff --git a/.changeset/empty-experts-unite.md b/.changeset/empty-experts-unite.md new file mode 100644 index 000000000..78d0f2e86 --- /dev/null +++ b/.changeset/empty-experts-unite.md @@ -0,0 +1,27 @@ +--- +'astro': minor +--- + +Persistent DOM and Islands in Experimental View Transitions + +With `viewTransitions: true` enabled in your Astro config's experimental section, pages using the `` routing component can now access a new `transition:persist` directive. + +With this directive, you can keep the state of DOM elements and islands on the old page when transitioning to the new page. + +For example, to keep a video playing across page navigation, add `transition:persist` to the element: + +```astro + +``` + +This `