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

Actions: Make .safe() the default return value #11571

Merged
merged 19 commits into from
Jul 30, 2024
Merged

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Jul 29, 2024

Changes

Make .safe() the default return value for actions. This means { data, error } will be returned when calling an action directly. If you prefer to get the data while allowing errors to throw, chain the .orThrow() modifier.

import { actions } from 'astro:actions';

// Before
const { data, error } = await actions.like.safe();
// After
const { data, error } = await actions.like();

// Before
const newLikes = await actions.like();
// After
const newLikes = await actions.like.orThrow();
  • Update types and implementation to reverse this pattern
  • Remove support for using unsafe action calls with React 19. Chaining .orThrow() will remove progressive enhancement, since exceptions must be caught on the client.

Testing

Update test fixtures to use the new API pattern.

Docs

RFC updates to be pushed on minor release

Copy link

changeset-bot bot commented Jul 29, 2024

🦋 Changeset detected

Latest commit: 05b163f

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: react Related to React (scope) pkg: integration Related to any renderer integration (scope) pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Jul 29, 2024
@bholmesdev bholmesdev changed the title Feat/action safe default Actions: Make .safe() the default return value Jul 29, 2024
@bholmesdev bholmesdev marked this pull request as ready for review July 29, 2024 21:01
@github-actions github-actions bot added the semver: minor Change triggers a `minor` release label Jul 29, 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.

.changeset/light-chairs-happen.md Outdated Show resolved Hide resolved
.changeset/light-chairs-happen.md Show resolved Hide resolved
@Princesseuh
Copy link
Member

Does this interact in any way with this issue? #11515

@bholmesdev
Copy link
Contributor Author

@Princesseuh Taking a look at that issue. This is switching a default, but wouldn't affect parsing behavior, so I don't believe so.

Base automatically changed from feat/new-action-fallback to main July 30, 2024 15:04
@bholmesdev bholmesdev force-pushed the feat/action-safe-default branch from 4035591 to 05b163f Compare July 30, 2024 15:13
@bholmesdev bholmesdev merged commit 1c3265a into main Jul 30, 2024
14 checks passed
@bholmesdev bholmesdev deleted the feat/action-safe-default branch July 30, 2024 15:42
@astrobot-houston astrobot-houston mentioned this pull request Jul 30, 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: integration Related to any renderer integration (scope) pkg: react Related to React (scope) pr: docs A PR that includes documentation for review semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants