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: add support for automatic session driver config #13145

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Feb 6, 2025

Changes

Automatically configures session storage with the Node and Netlify adapters. If theexperimental.session flag is enabled, the Node adapter will configure fs session storage and Netlify will configure netlify-blobs session storage.

This also changes the experimental.session option to a boolean flag and moves session config to a top-level value. Separating them is to allow users to enable it without needing to set the config, thus allowing for adapters and integrations to handle it.

You now need to separately enable the experimental.session flag, and then configure the session driver using the top-level session key if providing manual configuration.

defineConfig({
  // ...
  experimental: {
-    session: {
-      driver: 'fs',
-    },
+    session: true,
  },
+  session: {
+    driver: 'fs',
+  },
});

You do not need to configure the session driver if you are using the Node or Netlify adapters and want to use the default session drivers for each adapter. The default session driver for the Node adapter is fs, and the default session driver for the Netlify adapter is netlify-blobs.

For example, if you are using the Node adapter, you can just enable the flag:

defineConfig({
  // ...
  adapter: node({
    mode: 'standalone',
  }),
  experimental: {
    session: true,
  },
});

This will configure the session driver to use the default fs driver for the Node adapter. See the release notes for @astrojs/node and @astrojs/netlify for more information on the default session drivers for each adapter.

If you enable the flag but are using an adapter that does not have a default session driver, you will need to configure the session driver manually or the build will fail.

Testing

Added test cases for the Node and Netlify adapters. The Netlify tests use the local mock blobs server.

Docs

Updated the docs for the config options. This adds several new error types, so I have moved session errors into their own section. I will do a separate PR to the docs repo to update the experimental feature page.

Copy link

changeset-bot bot commented Feb 6, 2025

🦋 Changeset detected

Latest commit: d0fac27

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 semver: minor Change triggers a `minor` release labels Feb 6, 2025
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

codspeed-hq bot commented Feb 6, 2025

CodSpeed Performance Report

Merging #13145 will not alter performance

Comparing session-config2 (db89093) with main (7bc8256)

Summary

✅ 6 untouched benchmarks

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Feb 6, 2025
@ascorbic
Copy link
Contributor Author

ascorbic commented Feb 6, 2025

!preview adapter-sessions

@ascorbic ascorbic self-assigned this Feb 6, 2025
@ascorbic ascorbic marked this pull request as ready for review February 7, 2025 12:00
@ascorbic
Copy link
Contributor Author

ascorbic commented Feb 7, 2025

!preview adapter-sessions

Copy link
Contributor

github-actions bot commented Feb 7, 2025

❌ Snapshot release failed.

@ascorbic
Copy link
Contributor Author

ascorbic commented Feb 7, 2025

!preview adapter-sessions

Copy link
Contributor

github-actions bot commented Feb 7, 2025

Snapshots have been released for the following packages:

  • @astrojs/netlify@experimental--adapter-sessions
  • @astrojs/node@experimental--adapter-sessions
  • astro@experimental--adapter-sessions
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/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/adapter, @benchmark/timer, astro, create-astro
• Running build in 29 packages
• Remote caching enabled
::group::@astrojs/internal-helpers:build
cache hit, suppressing logs bcacf5caadbcee38
::endgroup::
::group::create-astro:build
cache hit, suppressing logs b08d1b7a4a5046a4
::endgroup::
::group::@astrojs/telemetry:build
cache hit, suppressing logs 3b3182f09cb263ad
::endgroup::
::group::@astrojs/prism:build
cache hit, suppressing logs 96482960d9e18b5b
::endgroup::
::group::@astrojs/upgrade:build
cache hit, suppressing logs fb8881c0b838c820
::endgroup::
::group::@astrojs/markdown-remark:build
cache hit, suppressing logs 6834652a85d79a58
::endgroup::
::group::astro:build
cache miss, executing 808006a8f0f8d219

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


> [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"

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

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

::endgroup::
::group::@astrojs/rss:build
cache miss, executing 8147134a9c668f09

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

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

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

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

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

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

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

::endgroup::
::group::@astrojs/alpinejs:build
cache miss, executing 7e855b97ed8a8b73

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

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

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

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

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

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

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

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

::endgroup::
::group::@benchmark/adapter:build
cache miss, executing 831cee16f188334c

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

::endgroup::
::group::@astrojs/node:build
cache miss, executing 7c6d79f5903918ee

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

::endgroup::
::group::@astrojs/vercel:build
cache miss, executing 800025cdd7ec45d7

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

::endgroup::
::group::@astrojs/mdx:build
cache miss, executing 2e89b979b00f440b

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

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

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

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

> @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/netlify:build
cache miss, executing 05f4839e65b49143

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

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

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

::endgroup::
::group::@astrojs/cloudflare:build
cache miss, executing 47753fa22d34024c

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

::endgroup::
::group::@astrojs/db:build
cache miss, executing 6ebe5f24bd050448

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

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

::endgroup::

 Tasks:    29 successful, 29 total
Cached:    6 cached, 29 total
  Time:    48.298s 
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--adapter-sessions 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/cloudflare
🦋  info npm info @astrojs/markdoc
🦋  info npm info @astrojs/mdx
🦋  info npm info @astrojs/netlify
🦋  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-adapter-sessions-20250207124921) has not been published on npm
🦋  warn @astrojs/prism is not being published because version 3.2.0 is already published on npm
🦋  warn @astrojs/rss is not being published because version 4.0.11 is already published on npm
🦋  warn create-astro is not being published because version 4.11.0 is already published on npm
🦋  warn @astrojs/db is not being published because version 0.14.6 is already published on npm
🦋  warn @astrojs/alpinejs is not being published because version 0.4.3 is already published on npm
🦋  warn @astrojs/cloudflare is not being published because version 12.2.1 is already published on npm
🦋  warn @astrojs/markdoc is not being published because version 0.12.9 is already published on npm
🦋  warn @astrojs/mdx is not being published because version 4.0.8 is already published on npm
🦋  info @astrojs/netlify is being published because our local version (0.0.0-adapter-sessions-20250207124921) has not been published on npm
🦋  info @astrojs/node is being published because our local version (0.0.0-adapter-sessions-20250207124921) has not been published on npm
🦋  warn @astrojs/partytown is not being published because version 2.1.3 is already published on npm
🦋  warn @astrojs/preact is not being published because version 4.0.4 is already published on npm
🦋  warn @astrojs/react is not being published because version 4.2.0 is already published on npm
🦋  warn @astrojs/sitemap is not being published because version 3.2.1 is already published on npm
🦋  warn @astrojs/solid-js is not being published because version 5.0.4 is already published on npm
🦋  warn @astrojs/svelte is not being published because version 7.0.4 is already published on npm
🦋  warn @astrojs/tailwind is not being published because version 6.0.0 is already published on npm
🦋  warn @astrojs/vercel is not being published because version 8.0.6 is already published on npm
🦋  warn @astrojs/vue is not being published because version 5.0.6 is already published on npm
🦋  warn @astrojs/web-vitals is not being published because version 3.0.1 is already published on npm
🦋  warn @astrojs/internal-helpers is not being published because version 0.5.1 is already published on npm
🦋  warn @astrojs/markdown-remark is not being published because version 6.1.0 is already published on npm
🦋  warn @astrojs/studio is not being published because version 0.1.4 is already published on npm
🦋  warn @astrojs/telemetry is not being published because version 3.2.0 is already published on npm
🦋  warn @astrojs/underscore-redirects is not being published because version 0.6.0 is already published on npm
🦋  warn @astrojs/upgrade is not being published because version 0.4.3 is already published on npm
🦋  info Publishing "astro" at "0.0.0-adapter-sessions-20250207124921"
🦋  info Publishing "@astrojs/netlify" at "0.0.0-adapter-sessions-20250207124921"
🦋  info Publishing "@astrojs/node" at "0.0.0-adapter-sessions-20250207124921"
🦋  success packages published successfully:
🦋  [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]

@ematipico
Copy link
Member

ematipico commented Feb 7, 2025

Astro.session was introduced in Astro v5.1.0. This means that the peerDependencies#astro of Node.js and Netlify should be bumped to 5.1.0

@ascorbic
Copy link
Contributor Author

ascorbic commented Feb 7, 2025

@ematipico I will actually bump it to 5.3.0, because this PR changes the API

.changeset/tricky-insects-argue.md Outdated Show resolved Hide resolved
.changeset/tricky-insects-argue.md Outdated Show resolved Hide resolved
return driver;
}

export function validateSessionConfig(settings: AstroSettings): void {
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we validate the configuration inside the zod schema using refine or superRefine?

EDIT: I understand why we need a function, I think it's worth adding a comment that explains that

packages/astro/src/types/public/config.ts 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.

Just a couple of thoughts on the breaking change changeset!

});
```

You do not need to configure the session driver if you are using an adapter that supports automatic session driver configuration. For more information, see the [experimental session docs](https://docs.astro.build/en/reference/experimental-flags/sessions/).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
You do not need to configure the session driver if you are using an adapter that supports automatic session driver configuration. For more information, see the [experimental session docs](https://docs.astro.build/en/reference/experimental-flags/sessions/).
You no longer need to configure a session driver if you are using an adapter that supports automatic session driver configuration and wish to use its default settings.
However, you can still manually configure additional driver options or choose a non-default driver to use with your adapter with the new top-level `session` config option. For more information, see the [experimental session docs](https://docs.astro.build/en/reference/experimental-flags/sessions/).

Just thought somewhere we could mention that there are options that someone might want to set for even the default supported driver? (If I have this right.) It's not that session is only for choosing a different driver, but for setting any options like the new ttl etc.


Changes the `experimental.session` option to a boolean flag and moves session config to a top-level value. This change is to allow the new automatic session driver support. You now need to separately enable the `experimental.session` flag, and then configure the session driver using the top-level `session` key if providing manual configuration.

```diff
Copy link
Member

Choose a reason for hiding this comment

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

Following on the previous comment, I would suggest that the code sample not just move fs out to session, but demonstrate either:

  • also showing an adapter like Netlify, so that it's clear that this is showing a non-default driver chosen OR
  • show either the Node or Netlify adapter and do NOT show configuring a driver, but some option like base etc. to reinforce that stating the driver isn't needed for these

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) pkg: integration Related to any renderer integration (scope) semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants