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

Server islands #11305

Merged
merged 31 commits into from
Jul 17, 2024
Merged

Server islands #11305

merged 31 commits into from
Jul 17, 2024

Conversation

matthewp
Copy link
Contributor

@matthewp matthewp commented Jun 20, 2024

API Bashing

Create a new Astro project as normal:

npm create astro@latest

After that has been created, install the preview release:

npm install astro@experimental--server-islands

To use server islands you need to set your output to 'hybrid' or 'server':

export default defineConfig({
  output: 'hybrid'
});

Then add server:defer to any component. You can provide fallback HTML that will be rendered on the initial request with slot="fallback":

<PersonalBar server:defer>
  <div slot="fallback">Loading</div>
</PersonalBar>

Changes

  • Adds a server:defer directive to allow deferred islands that are loaded from the server after the page loads.

Testing

TODO

Docs

TODO

Copy link

changeset-bot bot commented Jun 20, 2024

🦋 Changeset detected

Latest commit: a63ff42

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: example Related to an example package (scope) pkg: astro Related to the core `astro` package (scope) docs pr A PR that includes documentation for review labels Jun 20, 2024
packages/astro/package.json Outdated Show resolved Hide resolved
@matthewp
Copy link
Contributor Author

!preview server-islands

Copy link
Contributor

Snapshots have been released for the following packages:

  • @astrojs/markdown-remark@experimental--server-islands
  • @astrojs/underscore-redirects@experimental--server-islands
  • astro@experimental--server-islands
  • @astrojs/vercel@experimental--server-islands
  • @astrojs/node@experimental--server-islands
  • @astrojs/rss@experimental--server-islands
  • @astrojs/markdoc@experimental--server-islands
  • @astrojs/mdx@experimental--server-islands
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--server-islands tag
🦋  warn ----------------------------------------------------------------------
🦋  info npm info astro
🦋  info npm info @astrojs/prism
🦋  info npm info @astrojs/rss
🦋  info npm info create-astro
🦋  info npm info @astrojs/db
🦋  info npm info @astrojs/alpinejs
🦋  info npm info @astrojs/lit
🦋  info npm info @astrojs/markdoc
🦋  info npm info @astrojs/mdx
🦋  info npm info @astrojs/node
🦋  info npm info @astrojs/partytown
🦋  info npm info @astrojs/preact
🦋  info npm info @astrojs/react
🦋  info npm info @astrojs/sitemap
🦋  info npm info @astrojs/solid-js
🦋  info npm info @astrojs/svelte
🦋  info npm info @astrojs/tailwind
🦋  info npm info @astrojs/vercel
🦋  info npm info @astrojs/vue
🦋  info npm info @astrojs/web-vitals
🦋  info npm info @astrojs/internal-helpers
🦋  info npm info @astrojs/markdown-remark
🦋  info npm info @astrojs/studio
🦋  info npm info @astrojs/telemetry
🦋  info npm info @astrojs/underscore-redirects
🦋  info npm info @astrojs/upgrade
🦋  info astro is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  warn @astrojs/prism is not being published because version 3.1.0 is already published on npm
🦋  info @astrojs/rss is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  warn create-astro is not being published because version 4.8.0 is already published on npm
🦋  warn @astrojs/db is not being published because version 0.11.6 is already published on npm
🦋  warn @astrojs/alpinejs is not being published because version 0.4.0 is already published on npm
🦋  warn @astrojs/lit is not being published because version 4.3.0 is already published on npm
🦋  info @astrojs/markdoc is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  info @astrojs/mdx is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  info @astrojs/node is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  warn @astrojs/partytown is not being published because version 2.1.1 is already published on npm
🦋  warn @astrojs/preact is not being published because version 3.5.0 is already published on npm
🦋  warn @astrojs/react is not being published because version 3.6.0 is already published on npm
🦋  warn @astrojs/sitemap is not being published because version 3.1.6 is already published on npm
🦋  warn @astrojs/solid-js is not being published because version 4.4.0 is already published on npm
🦋  warn @astrojs/svelte is not being published because version 5.6.0 is already published on npm
🦋  warn @astrojs/tailwind is not being published because version 5.1.0 is already published on npm
🦋  info @astrojs/vercel is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  warn @astrojs/vue is not being published because version 4.5.0 is already published on npm
🦋  warn @astrojs/web-vitals is not being published because version 0.2.1 is already published on npm
🦋  warn @astrojs/internal-helpers is not being published because version 0.4.0 is already published on npm
🦋  info @astrojs/markdown-remark is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  warn @astrojs/studio is not being published because version 0.1.0 is already published on npm
🦋  warn @astrojs/telemetry is not being published because version 3.1.0 is already published on npm
🦋  info @astrojs/underscore-redirects is being published because our local version (0.0.0-server-islands-20240621194657) has not been published on npm
🦋  warn @astrojs/upgrade is not being published because version 0.3.1 is already published on npm
🦋  info Publishing "astro" at "0.0.0-server-islands-20240621194657"
🦋  info Publishing "@astrojs/rss" at "0.0.0-server-islands-20240621194657"
🦋  info Publishing "@astrojs/markdoc" at "0.0.0-server-islands-20240621194657"
🦋  info Publishing "@astrojs/mdx" at "0.0.0-server-islands-20240621194657"
🦋  info Publishing "@astrojs/node" at "0.0.0-server-islands-20240621194657"
🦋  info Publishing "@astrojs/vercel" at "0.0.0-server-islands-20240621194657"
🦋  info Publishing "@astrojs/markdown-remark" at "0.0.0-server-islands-20240621194657"
🦋  info Publishing "@astrojs/underscore-redirects" at "0.0.0-server-islands-20240621194657"
🦋  success packages published successfully:
🦋  [email protected]
🦋  @astrojs/[email protected]
🦋  @astrojs/[email protected]
🦋  @astrojs/[email protected]
🦋  @astrojs/[email protected]
🦋  @astrojs/[email protected]
🦋  @astrojs/[email protected]
🦋  @astrojs/[email protected]
🦋  Creating git tags...
🦋  New tag:  [email protected]
🦋  New tag:  @astrojs/[email protected]
🦋  New tag:  @astrojs/[email protected]
🦋  New tag:  @astrojs/[email protected]
🦋  New tag:  @astrojs/[email protected]
🦋  New tag:  @astrojs/[email protected]
🦋  New tag:  @astrojs/[email protected]
🦋  New tag:  @astrojs/[email protected]
Build Log

> [email protected] build /home/runner/work/astro/astro
> turbo run build --filter=astro --filter=create-astro --filter="@astrojs/*" --filter="@benchmark/*"

• Packages in scope: @astrojs/alpinejs, @astrojs/cloudflare, @astrojs/db, @astrojs/internal-helpers, @astrojs/lit, @astrojs/markdoc, @astrojs/markdown-remark, @astrojs/mdx, @astrojs/netlify, @astrojs/node, @astrojs/partytown, @astrojs/preact, @astrojs/prism, @astrojs/react, @astrojs/rss, @astrojs/sitemap, @astrojs/solid-js, @astrojs/studio, @astrojs/svelte, @astrojs/tailwind, @astrojs/telemetry, @astrojs/underscore-redirects, @astrojs/upgrade, @astrojs/vercel, @astrojs/vue, @astrojs/web-vitals, @benchmark/timer, astro, create-astro
• Running build in 29 packages
• Remote caching enabled
::group::@astrojs/telemetry:build
cache miss, executing 4be50575ed7cb189

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/telemetry
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/internal-helpers:build
cache miss, executing 18e3cc17afd46e2c

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/internal-helpers
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json


> @astrojs/[email protected] postbuild /home/runner/work/astro/astro/packages/internal-helpers
> astro-scripts copy "src/**/*.js"

::endgroup::
::group::@astrojs/upgrade:build
cache miss, executing c9c29891ecc45e55

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/upgrade
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::@astrojs/prism:build
cache miss, executing 07d34a42b62af751

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/astro-prism
> astro-scripts build "src/**/*.ts" && tsc -p ./tsconfig.json

::endgroup::
::group::create-astro:build
cache miss, executing a97fcbb089c59091

> [email protected] build /home/runner/work/astro/astro/packages/create-astro
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::@astrojs/markdown-remark:build
cache miss, executing c99eae8875242790

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/markdown/remark
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json


> @astrojs/[email protected] postbuild /home/runner/work/astro/astro/packages/markdown/remark
> astro-scripts copy "src/**/*.js"

::endgroup::
::group::astro:build
cache miss, executing 37472f06da709b17

> [email protected] build /home/runner/work/astro/astro/packages/astro
> pnpm run prebuild && astro-scripts build "src/**/*.{ts,js}" && tsc && pnpm run postbuild


> [email protected] prebuild /home/runner/work/astro/astro/packages/astro
> astro-scripts prebuild --to-string "src/runtime/server/astro-island.ts" "src/runtime/client/{idle,load,media,only,visible}.ts"


> [email protected] postbuild /home/runner/work/astro/astro/packages/astro
> astro-scripts copy "src/**/*.astro" && astro-scripts copy "src/**/*.wasm"

::endgroup::
::group::@astrojs/studio:build
cache miss, executing f8da3be51b2fde41

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/studio
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@benchmark/timer:build
cache miss, executing df8e98e3d7484853

> @benchmark/[email protected] build /home/runner/work/astro/astro/benchmark/packages/timer
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/partytown:build
cache miss, executing 5c09bdaa72561292

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/partytown
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/react:build
cache miss, executing df6797c217421193

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/react
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/node:build
cache miss, executing 1d2fd87798902d06

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/node
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/tailwind:build
cache miss, executing 1b40813ec37952d5

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/tailwind
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/solid-js:build
cache miss, executing 376b09937d02e2b3

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/solid
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/vercel:build
cache miss, executing 832adde3894fdac9

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/vercel
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/preact:build
cache miss, executing ab26f06249731707

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/preact
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/vue:build
cache miss, executing 65256b136068712e

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/vue
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/rss:build
cache miss, executing 97f1f04e921d88ff

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/astro-rss
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/lit:build
cache miss, executing 1230fa80b5c49b67

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/lit
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/alpinejs:build
cache miss, executing 2aec458d3c5d818f

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/alpinejs
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/markdoc:build
cache miss, executing 77b00c603471e771

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/markdoc
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/underscore-redirects:build
cache miss, executing 8be90d23b7df6e24

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/underscore-redirects
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json


> @astrojs/[email protected] postbuild /home/runner/work/astro/astro/packages/underscore-redirects
> astro-scripts copy "src/**/*.js"

::endgroup::
::group::@astrojs/sitemap:build
cache miss, executing c39e4237bcf26331

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/sitemap
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/mdx:build
cache miss, executing 3fdaab21fcad1ecf

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/mdx
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/svelte:build
cache miss, executing f8ad6a40d39ed935

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/svelte
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/db:build
cache miss, executing 2c5d1d2f07248bff

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/db
> astro-scripts build "src/**/*.ts" && tsc && pnpm types:virtual


> @astrojs/[email protected] types:virtual /home/runner/work/astro/astro/packages/db
> tsc -p ./tsconfig.virtual.json

::endgroup::
::group::@astrojs/web-vitals:build
cache miss, executing 3a16668716ba452d

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/web-vitals
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::

 Tasks:    27 successful, 27 total
Cached:    0 cached, 27 total
  Time:    57.856s 

@Fryuni
Copy link
Member

Fryuni commented Jun 25, 2024

Astro.self is failing with the following error:

Error: Could not find server component name
    at Object.render (/project/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/astro/dist/runtime/server/render/server-islands.js:19:15)
    at Module.renderChild (/project/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/astro/dist/runtime/server/render/any.js:31:17)

This alternative gives the expected result for a recursive component:

---
import Self from './Foo.astro'; // Name of the file where this is on
import * as timers from 'node:timers/promises';

await timers.setTimeout(1000);

const now = Date();
---
<p>
  {now}
</p>
{!Astro.props.stop && <Self stop server:defer />}

@matthewp
Copy link
Contributor Author

Does that work normally? I was trying to use Astro.self but you are importing yourself (if I understand correctly). I have never done that before, that works in normal code?

@Fryuni
Copy link
Member

Fryuni commented Jun 25, 2024

Yes, without server:defer both using Astro.self and importing yourself works.

@Fryuni
Copy link
Member

Fryuni commented Jun 25, 2024

Server island is not triggered if it is added to the document from a client island:

---
import Foo from '../components/Foo.astro';
import Preact from '../components/Preact.tsx';
---
<Preact client:only="preact">
	<Foo server:defer />
</Preact>

The script is added to the page but nothing happens:
image

(Haven't tested with other frameworks, only preact)

The inverse, a client:only inside of a server:defer, works fine

@misl-smlz
Copy link

Can the example be extended to several pages (e.g. online shop items 1, 2 and 3)? This would allow you to see how the server-islands behave when changing pages and consider how you could eliminate the (probable) flickering, e.g. at the count.

@Mouaz
Copy link

Mouaz commented Jun 28, 2024

Great work here! however it would be better if there's some sort of client persistence/caching mechanism. It'd be too server consuming to load the server island on every navigation.

I suggest adding a client:persist directive.

@matthewp
Copy link
Contributor Author

@Mouaz that will work if you use the <ViewTransitions /> router already, I believe.

* Add support for the build to Server Islands

* Use command instead

* editor tips

* Add comment about defaultRoutes

* Use renderChunk instead of generateBundle
@ascorbic
Copy link
Contributor

ascorbic commented Jul 3, 2024

!preview server-islands

@matthewp matthewp marked this pull request as ready for review July 16, 2024 20:14
@sarah11918
Copy link
Member

Just noting there's no changeset yet, which I'd normally look over too. But, docs are approved, and we usually use some manner of copy/paste of those, so would be straightforward to pull from there when it's time.

That's the only reason there's no explicit docs approval here! The in-docs docs are good to on my end.

(Also just confirming that I didn't see any new error messages introduced with this!)

@github-actions github-actions bot added the semver: minor Change triggers a `minor` release label Jul 17, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Just some suggestions to consider here @matthewp !

  • link to docs is always good! (your call if you want the RFC, blog post etc. Note: docs will have the RFC link there)
  • added concepts (without going into details) of needing both a server rendered mode and fallback content
  • Chose a bit more active phrase to hint at "turning existing components into" vs another more definition-y "server islands are" Just feels a bit more exciting! And easy to do!

.changeset/five-rocks-vanish.md Outdated Show resolved Hide resolved
.changeset/five-rocks-vanish.md Outdated Show resolved Hide resolved
.changeset/five-rocks-vanish.md Show resolved Hide resolved
.changeset/five-rocks-vanish.md Outdated Show resolved Hide resolved
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Approving for docs! 🥳

@matthewp matthewp merged commit d495df5 into main Jul 17, 2024
13 of 14 checks passed
@matthewp matthewp deleted the server-islands branch July 17, 2024 17:37
@astrobot-houston astrobot-houston mentioned this pull request Jul 17, 2024
ematipico pushed a commit that referenced this pull request Jul 18, 2024
* Spike

* Server Islands

* Remove extra stuff

* Fix build, a little

* Fix build

* astro metadata can be undefined

* Add server:defer type

* Add support for the build to Server Islands (#11372)

* Add support for the build to Server Islands

* Use command instead

* editor tips

* Add comment about defaultRoutes

* Use renderChunk instead of generateBundle

* Server islands tests (#11405)

* Add support for the build to Server Islands

* Use command instead

* editor tips

* Add comment about defaultRoutes

* Use renderChunk instead of generateBundle

* Adds tests for server islands

* linting

* Pass slots to server islands (#11431)

* Require the experimental flag to use server islands (#11432)

* Require the experimental flag to use server islands

* Add flag to tests/examples

* Protect SSR against SI not being enabled

* Update the docs in the API ref

* Upgrade to compiler 2.9.0

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update packages/astro/src/@types/astro.ts

Co-authored-by: Sarah Rainsberger <[email protected]>

* Fix lockfile

* Add a changeset

* Update .changeset/five-rocks-vanish.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/five-rocks-vanish.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/five-rocks-vanish.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update .changeset/five-rocks-vanish.md

Co-authored-by: Sarah Rainsberger <[email protected]>

* Update lockfile

* Update .changeset/five-rocks-vanish.md

Co-authored-by: Sarah Rainsberger <[email protected]>

---------

Co-authored-by: Sarah Rainsberger <[email protected]>
@astrobot-houston astrobot-houston mentioned this pull request Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs pr A PR that includes documentation for review pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants