Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline hydration directive scripts #3605

Merged
merged 3 commits into from
Jun 16, 2022
Merged

Inline hydration directive scripts #3605

merged 3 commits into from
Jun 16, 2022

Conversation

matthewp
Copy link
Contributor

Changes

  • Moves hydration directive scripts to be inlined into the page.
    • The first time a hydrated component is encountered, the hydration directive and the astro-island script are inlined together.
    • For any future hydrated components, if the directive has not been encountered before it will be inlined in a new script.
    • The total number of scripts is N where N is the number of directives used on the page.
  • Each directive is added to the global object, Astro.load, Astro.idle, etc.

Testing

  • No new tests needed for this, existing tests should continue to pass.

Docs

N/A, perf optimization.

@changeset-bot
Copy link

changeset-bot bot commented Jun 15, 2022

🦋 Changeset detected

Latest commit: 86b1e85

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 15, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 15, 2022

⚖️ Bundle Size Check

Latest commit: 86b1e85

File Old Size New Size Change
hydration-directives.d 0 B 12 B + 12 B
client:idle 471 B 165 B - NaN undefined
client:load 375 B 82 B - NaN undefined
client:media 486 B 185 B - NaN undefined
client:only 375 B 82 B - NaN undefined
client:visible 584 B 263 B - NaN undefined

@okikio
Copy link
Member

okikio commented Jun 15, 2022

I'm really excited for this, it'll boost perfs when using lots of components.

@matthewp matthewp marked this pull request as ready for review June 15, 2022 20:21
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍 This is very cool! Nice work!

@@ -2,6 +2,16 @@
// Do not import this file directly, instead import the prebuilt one instead.
// pnpm --filter astro run prebuild

type directiveAstroKeys = string;
Copy link
Member

@natemoo-re natemoo-re Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be the specific hydration method names rather than string?

Copy link
Contributor Author

@matthewp matthewp Jun 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking here was that we might support custom directives in the future and then this might actually be any string. But I didn't really think this all the way through so this might be too confusing as is, will change it.

@matthewp matthewp merged commit 4916b73 into main Jun 16, 2022
@matthewp matthewp deleted the inline-hydration-script branch June 16, 2022 13:54
@github-actions github-actions bot mentioned this pull request Jun 16, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Inline hydration scripts

* Adds a changeset

* Update directiveAstroKeys type
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Inline hydration scripts

* Adds a changeset

* Update directiveAstroKeys type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants