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

feat: container APIs #11051

Merged
merged 29 commits into from
May 22, 2024
Merged

feat: container APIs #11051

merged 29 commits into from
May 22, 2024

Conversation

ematipico
Copy link
Member

@ematipico ematipico commented May 15, 2024

Changes

Relative RFC: withastro/roadmap#916 (this RFC will be soon updated based on the APIs and options crafted in this PR)

As for now, we publicly expose the following methods:

  • create: creates a new instance of the container
  • renderToString: renders a component to string
  • renderToResponse: returns the response emitted by the rendering phase

The methods insertRoute and createFromManifest were left private using TS on purpose because I still want them available so I can still play with them without breaking the compatibility with end users.

The goal is to provide, for now, the ability to test components with vitest. This would allow us to quickly release the APIs and receive feedback.

Testing

Added unit tests and example tests

Docs

withastro/docs#8281

/cc @withastro/maintainers-docs for feedback!

Copy link

changeset-bot bot commented May 15, 2024

🦋 Changeset detected

Latest commit: 239a41c

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

@ematipico ematipico changed the title Feat/container api feat: container APIs May 15, 2024
@github-actions github-actions bot added pkg: example Related to an example package (scope) pkg: astro Related to the core `astro` package (scope) semver: minor Change triggers a `minor` release labels May 15, 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.

@ematipico
Copy link
Member Author

!preview container

Copy link
Contributor

Snapshots have been released for the following packages:

  • astro@experimental--container
  • @astrojs/db@experimental--container
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--container 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/telemetry
🦋  info npm info @astrojs/underscore-redirects
🦋  info npm info @astrojs/upgrade
🦋  info astro is being published because our local version (0.0.0-container-20240515090348) has not been published on npm
🦋  warn @astrojs/prism is not being published because version 3.1.0 is already published on npm
🦋  warn @astrojs/rss is not being published because version 4.0.5 is already published on npm
🦋  warn create-astro is not being published because version 4.8.0 is already published on npm
🦋  info @astrojs/db is being published because our local version (0.0.0-container-20240515090348) has not been 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.0.1 is already published on npm
🦋  warn @astrojs/markdoc is not being published because version 0.11.0 is already published on npm
🦋  warn @astrojs/mdx is not being published because version 3.0.0 is already published on npm
🦋  warn @astrojs/node is not being published because version 8.2.5 is already published on npm
🦋  warn @astrojs/partytown is not being published because version 2.1.0 is already published on npm
🦋  warn @astrojs/preact is not being published because version 3.3.0 is already published on npm
🦋  warn @astrojs/react is not being published because version 3.3.4 is already published on npm
🦋  warn @astrojs/sitemap is not being published because version 3.1.4 is already published on npm
🦋  warn @astrojs/solid-js is not being published because version 4.2.0 is already published on npm
🦋  warn @astrojs/svelte is not being published because version 5.4.0 is already published on npm
🦋  warn @astrojs/tailwind is not being published because version 5.1.0 is already published on npm
🦋  warn @astrojs/vercel is not being published because version 7.6.0 is already published on npm
🦋  warn @astrojs/vue is not being published because version 4.2.0 is already published on npm
🦋  warn @astrojs/web-vitals is not being published because version 0.1.1 is already published on npm
🦋  warn @astrojs/internal-helpers is not being published because version 0.4.0 is already published on npm
🦋  warn @astrojs/markdown-remark is not being published because version 5.1.0 is already published on npm
🦋  warn @astrojs/telemetry is not being published because version 3.1.0 is already published on npm
🦋  warn @astrojs/underscore-redirects is not being published because version 0.3.3 is already published on npm
🦋  warn @astrojs/upgrade is not being published because version 0.3.0 is already published on npm
🦋  info Publishing "astro" at "0.0.0-container-20240515090348"
🦋  info Publishing "@astrojs/db" at "0.0.0-container-20240515090348"
🦋  success packages published successfully:
🦋  [email protected]
🦋  @astrojs/[email protected]
🦋  Creating git tags...
🦋  New tag:  [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/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 28 packages
• Remote caching enabled
::group::@astrojs/telemetry:build
cache hit, suppressing logs 95bd2f8cbca89f97
::endgroup::
::group::@astrojs/upgrade:build
cache hit, suppressing logs 72c72bf9c48ba3e0
::endgroup::
::group::@astrojs/prism:build
cache hit, suppressing logs 601194e64df38a11
::endgroup::
::group::@astrojs/markdown-remark:build
cache hit, suppressing logs 09627d1426328c42
::endgroup::
::group::@astrojs/internal-helpers:build
cache hit, suppressing logs eb5867eac3983ee3
::endgroup::
::group::create-astro:build
cache hit, suppressing logs 785aab1edd72bb57
::endgroup::
::group::astro:build
cache miss, executing 41f1f296ef790dbc

> [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/lit:build
cache miss, executing 38436369f51c79f1

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

::endgroup::
::group::@astrojs/rss:build
cache miss, executing 0aeb4ba0cb78f9a1

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

::endgroup::
::group::@astrojs/tailwind:build
cache miss, executing 17e827aef537af4e

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

::endgroup::
::group::@astrojs/node:build
cache miss, executing 08d9bc022de4efbd

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

::endgroup::
::group::@astrojs/solid-js:build
cache miss, executing 577204d65b9b97b2

> @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 0818638153cf0e3a

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

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

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

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

> @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/vue:build
cache miss, executing 0f02b0674a0aa363

> @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/alpinejs:build
cache miss, executing 37cab48db8a69dfb

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

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

> @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 a8e019c5299ce2e7

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

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

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

::endgroup::
::group::@astrojs/underscore-redirects:build
cache miss, executing 018bee54c2b9f130

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

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

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

::endgroup::
::group::@astrojs/mdx:build
cache miss, executing 1482d8c0a42db0c0

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

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

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

::endgroup::
::group::@astrojs/db:build
cache miss, executing 1659e77825c3b9e1

> @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 18187a63b0a63400

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

::endgroup::

 Tasks:    26 successful, 26 total
Cached:    6 cached, 26 total
  Time:    47.727s 

@ematipico ematipico marked this pull request as ready for review May 15, 2024 09:34
@ematipico ematipico added this to the 4.9.0 milestone May 15, 2024
*
*
* @param {AstroComponentFactory} component The instance of the component.
* @param {ContainerRenderOptions=} options Possible options to pass when rendering the component.
Copy link
Member

Choose a reason for hiding this comment

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

What's this = at the end of the type? Saw it in a few places

Copy link
Member

Choose a reason for hiding this comment

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

With TSDoc, we should also be able to remove the type altogether so we don't have to declare it in two places.

Copy link
Member Author

@ematipico ematipico May 15, 2024

Choose a reason for hiding this comment

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

@Princesseuh It's a JSDoc thing to mark a @param as optional

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.

I think I mostly only need to look at the changeset in this PR, but here are some suggestions re: what I was thinking, to give you an idea!

See what you think, and edit/take from it whatever you like!

"test": "vitest run"
},
"dependencies": {
"astro": "experimental--container",
Copy link
Member

Choose a reason for hiding this comment

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

Just want to check on this. Will this be the "version" of Astro to use for this starter when 4.9 is out? But, it's not an experimental flag people have to enable in config?

Copy link
Member Author

@ematipico ematipico May 17, 2024

Choose a reason for hiding this comment

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

This is required for the time being, otherwise astro check will fail, which is run in our CI. We will change this straight after we will release v4.9

*/
params?: Record<string, string | undefined>;
/**
* Useful if your component needs to access some locals without the use a middleware.
Copy link
Member

Choose a reason for hiding this comment

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

Just a quick note here that I did some editing of descriptions for these in the Container API page PR for docs. These could always be revisited after that is finalized, and/or these could have links to docs (not sure what the proper/usual M.O. is here with these code comments as I don't usually edit them).

But, I have made some suggestions in the docs PR itself for these!

.changeset/brave-colts-cover.md Show resolved Hide resolved
.changeset/brave-colts-cover.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.

Changeset looks good to me, so if everyone is happy with its content, consider it approved by docs!


componentMetadata(_routeData: RouteData): Promise<SSRResult['componentMetadata']> | void {}

headElements(routeData: RouteData): Promise<HeadElements> | HeadElements {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this function used for?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I see now that this is called when the render context is created.

Copy link
Member Author

Choose a reason for hiding this comment

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

I used some code we already use in dev/build/ssr. We will probably need to review it in case it causes bugs.

@ematipico ematipico merged commit 12a1bcc into main May 22, 2024
14 checks passed
@ematipico ematipico deleted the feat/container-api branch May 22, 2024 11:11
@astrobot-houston astrobot-houston mentioned this pull request May 22, 2024
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) 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.

5 participants