From 0a7b6deaec9fa32c2cb7139ac9aeaa242c0a7f4c Mon Sep 17 00:00:00 2001
From: Tony Sullivan
Date: Thu, 8 Jul 2021 20:07:56 +0200
Subject: [PATCH] Move hydration directives to special attributes (#618)
* feat: :recycle: updating hydration to work with the directive syntax
* test: :white_check_mark: Updating tests for the hydration directive syntax
* refactor: Updating example projects for the hydration directive syntax
* test: :white_check_mark: Found a test fixture still needing an update to the hydration directive syntax
* style: Prettier strikes again! Reverting code formatting changes
* refactor: :recycle: moving directive matching to a Set
* refactor: Updating syntax to `client:load`
* refactor: :recycle: Simplifying the `client:` directive match
Per PR feedback from @matthewp
* chore: errant console.warn() snuck into the last commit
* feat: :loud_sound: Adding a super fancy build warning to update to the directive syntax
* refactor: :recycle: Removing unnecessary checks when matching supported hydration directives
`val` isn't being used for now, but leaving it in the attr destructuring as a reminder since it'll be needed for `client:media`
* test: :white_check_mark: Including the original hydration syntax in a test to make sure it builds
* style: :memo: Adding a comment to make it clear why the old hydration syntax is included in a the test markup
* fix: :bug: updating `head` logic to recognize hydration directive syntax
* docs: Adding changeset
* refactor: :fire: Removing unnecessary `!hasComponents` check
* docs: :memo: Adding more detail to the changset
Co-authored-by: Tony Sullivan
---
.changeset/famous-years-bow.md | 15 +++++
.../blog/src/pages/posts/introducing-astro.md | 2 +-
examples/docs/src/layouts/Main.astro | 4 +-
.../framework-multiple/src/pages/index.astro | 16 ++---
.../framework-preact/src/pages/index.astro | 4 +-
.../framework-react/src/pages/index.astro | 4 +-
.../framework-svelte/src/pages/index.astro | 4 +-
examples/framework-vue/src/pages/index.astro | 4 +-
examples/snowpack/src/pages/news.astro | 2 +-
examples/snowpack/src/pages/plugins.astro | 2 +-
examples/with-markdown/src/pages/index.astro | 12 ++--
.../with-nanostores/src/pages/index.astro | 8 +--
packages/astro/README.md | 6 +-
packages/astro/src/compiler/codegen/index.ts | 58 ++++++++++++++-----
packages/astro/src/compiler/transform/head.ts | 12 +++-
.../astro-basic/src/pages/client.astro | 2 +-
.../src/pages/default-rename.astro | 4 +-
.../astro-dynamic/src/pages/index.astro | 3 +-
.../astro-fallback/src/pages/index.astro | 2 +-
.../fixtures/astro-hmr/src/pages/index.astro | 2 +-
.../fixtures/astro-hmr/src/pages/manual.astro | 2 +-
.../astro-markdown/src/pages/complex.astro | 2 +-
.../custom-elements/src/pages/load.astro | 2 +-
.../no-head-el/src/components/Child.astro | 2 +-
.../fixtures/no-head-el/src/pages/index.astro | 2 +-
25 files changed, 117 insertions(+), 59 deletions(-)
create mode 100644 .changeset/famous-years-bow.md
diff --git a/.changeset/famous-years-bow.md b/.changeset/famous-years-bow.md
new file mode 100644
index 000000000..77bf5d2c7
--- /dev/null
+++ b/.changeset/famous-years-bow.md
@@ -0,0 +1,15 @@
+---
+'astro': minor
+---
+
+## Adds directive syntax for component hydration
+
+This change updates the syntax for partial hydration from `` to ``.
+
+**Why?**
+
+Partial hydration is about to get super powers! This clears the way for more dynamic partial hydration, i.e. ``.
+
+**How to upgrade**
+
+Just update `:load`, `:idle`, and `:visible` to match the `client:load` format, thats it! Don't worry, the original syntax is still supported but it's recommended to future-proof your project by updating to the newer syntax.
diff --git a/examples/blog/src/pages/posts/introducing-astro.md b/examples/blog/src/pages/posts/introducing-astro.md
index 3f30087a1..293b3b8f9 100644
--- a/examples/blog/src/pages/posts/introducing-astro.md
+++ b/examples/blog/src/pages/posts/introducing-astro.md
@@ -54,7 +54,7 @@ Of course, sometimes client-side JavaScript is inevitable. Image carousels, shop
In other full-stack web frameworks this level of per-component optimization would be impossible without loading the entire page in JavaScript, delaying interactivity. In Astro, this kind of [partial hydration](https://addyosmani.com/blog/rehydration/) is built into the tool itself.
-You can even [automatically defer components](https://codepen.io/jonneal/full/ZELvMvw) to only load once they become visible on the page with the `:visible` modifier.
+You can even [automatically defer components](https://codepen.io/jonneal/full/ZELvMvw) to only load once they become visible on the page with the `client:visible` directive.
This new approach to web architecture is called [islands architecture](https://jasonformat.com/islands-architecture/). We didn't coin the term, but Astro may have perfected the technique. We are confident that an HTML-first, JavaScript-only-as-needed approach is the best solution for the majority of content-based websites.
diff --git a/examples/docs/src/layouts/Main.astro b/examples/docs/src/layouts/Main.astro
index a92ffaff4..dbfc90791 100644
--- a/examples/docs/src/layouts/Main.astro
+++ b/examples/docs/src/layouts/Main.astro
@@ -212,7 +212,7 @@ const githubEditUrl = `https://github.com/USER/REPO/blob/main/${currentFile}`