-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actions: Make
.safe()
the default return value (#11571)
* feat: new orThrow types * fix: parens on return type * feat: switch implementation to orThrow() * feat(e2e): update PostComment * fix: remove callSafely from middleware * fix: toString() for actions * fix(e2e): more orThrow updates * feat: remove progressive enhancement from orThrow * fix: remove _astroActionSafe handler from react * feat(e2e): update test to use safe calling * chore: console log * chore: unused import * fix: add rewriting: true to test fixture * fix: correctly throw for server-only actions * chore: changeset * fix: update type tests * fix(test): remove .safe() chain * docs: use "patch" with BREAKING CHANGE notice * docs: clarify react integration in changeset
- Loading branch information
1 parent
a77ed84
commit 1c3265a
Showing
16 changed files
with
105 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
'@astrojs/react': patch | ||
'astro': patch | ||
--- | ||
|
||
**BREAKING CHANGE to the experimental Actions API only.** Install the latest `@astrojs/react` integration as well if you're using React 19 features. | ||
|
||
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. | ||
|
||
```ts | ||
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(); | ||
``` | ||
|
||
## Migration | ||
|
||
To migrate your existing action calls: | ||
|
||
- Remove `.safe` from existing _safe_ action calls | ||
- Add `.orThrow` to existing _unsafe_ action calls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
packages/astro/test/fixtures/actions/src/pages/subscribe.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
--- | ||
import { actions } from 'astro:actions'; | ||
const { url, channel } = await actions.subscribeFromServer({ | ||
const res = await actions.subscribeFromServer.orThrow({ | ||
channel: 'bholmesdev', | ||
}); | ||
--- | ||
|
||
<p data-url>{url}</p> | ||
<p data-channel>{channel}</p> | ||
<p data-url>{res.url}</p> | ||
<p data-channel>{res.channel}</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters