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

fix: extract shared logic for server island loading into a function and only include it once #13576

Merged
merged 7 commits into from
Apr 11, 2025

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Apr 7, 2025

Changes

Currently, each server island includes a script to load its own content. That includes quite a bit of logic that could be shared between islands. This PR extracts that into a function that can be reused by each island, and includes it only once. This runtime script is defined as a classic, non-module script so that we can guarantee that it has always executed before any of the module scripts runs.

Testing

Added and updated tests

Docs

Copy link

changeset-bot bot commented Apr 7, 2025

🦋 Changeset detected

Latest commit: c297c5c

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

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 pkg: astro Related to the core `astro` package (scope) docs pr labels Apr 7, 2025
@ascorbic ascorbic added the pr preview This PR has a preview release label Apr 7, 2025
@github-actions github-actions bot removed the pr preview This PR has a preview release label Apr 7, 2025
Copy link

pkg-pr-new bot commented Apr 7, 2025

astro

npm i https://pkg.pr.new/astro@13576

@astrojs/cloudflare

npm i https://pkg.pr.new/@astrojs/cloudflare@13576

@astrojs/netlify

npm i https://pkg.pr.new/@astrojs/netlify@13576

@astrojs/node

npm i https://pkg.pr.new/@astrojs/node@13576

@astrojs/vercel

npm i https://pkg.pr.new/@astrojs/vercel@13576

commit: 9d93448

Copy link

codspeed-hq bot commented Apr 7, 2025

CodSpeed Performance Report

Merging #13576 will not alter performance

Comparing si-dedupe (c297c5c) with main (a0774b3)

Summary

✅ 6 untouched benchmarks

@ascorbic ascorbic marked this pull request as ready for review April 8, 2025 09:21
@ascorbic ascorbic changed the title fix: only include server island script once fix: extract shared logic for server island loading into a function and only include it once Apr 8, 2025
@ascorbic ascorbic requested a review from matthewp April 8, 2025 09:24
@matthewp
Copy link
Contributor

matthewp commented Apr 8, 2025

I would suggest using the render instruction for this, this is how we do the same thing to only render the hydration scripts once. The advantage is that you know for sure that the script is always rendered before the usage. I know that in this case we're using module scripts, but if you ever want to change that in the future you'd want to use render instructions instead.

Here's an example of the usage in hydration scripts.

@ascorbic ascorbic self-assigned this Apr 9, 2025
@ascorbic ascorbic requested a review from matthewp April 11, 2025 09:47
@ascorbic ascorbic merged commit 1c60ec3 into main Apr 11, 2025
6 checks passed
@ascorbic ascorbic deleted the si-dedupe branch April 11, 2025 14:26
@astrobot-houston astrobot-houston mentioned this pull request Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants