-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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: Add devalue
for serializing complex values
#11593
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6094252
wip: move getActionResult setup to render
bholmesdev 80c880e
feat: serialize action data for edge
bholmesdev ca27f57
refactor: serializeActionResult util
bholmesdev f59e2b1
feat: introduce devalue for body parsing
bholmesdev 55db79b
refactor: orthrow -> main
bholmesdev dc6dfac
feat(test): Date and Set
bholmesdev a3d8fac
refactor: move getAction to separate file for bundling
bholmesdev bf0c84e
docs: changeset
bholmesdev 4c60b11
Revert "refactor: move getAction to separate file for bundling"
bholmesdev 0958bba
Revert "Revert "refactor: move getAction to separate file for bundling""
bholmesdev c65dd32
fix: actions import from client
bholmesdev 5f4b527
feat: add support for URL objects
bholmesdev cb5b7fe
refactor: new isActionError utility
bholmesdev 416d147
refactor: reuse isInputError in fromJson
bholmesdev c4130c7
fix: use INTERNAL_SERVER_ERROR for unknown errors
bholmesdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Adds support for `Date()`, `Map()`, and `Set()` from action results. See [devalue](https://github.com/Rich-Harris/devalue) for a complete list of supported values. | ||
|
||
Also fixes serialization exceptions when deploying Actions with edge middleware on Netlify and Vercel. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { ZodType } from 'zod'; | ||
import type { ActionAccept, ActionClient } from './server.js'; | ||
|
||
/** | ||
* Get server-side action based on the route path. | ||
* Imports from the virtual module `astro:internal-actions`, which maps to | ||
* the user's `src/actions/index.ts` file at build-time. | ||
*/ | ||
export async function getAction( | ||
path: string | ||
): Promise<ActionClient<unknown, ActionAccept, ZodType> | undefined> { | ||
const pathKeys = path.replace('/_actions/', '').split('.'); | ||
// @ts-expect-error virtual module | ||
let { server: actionLookup } = await import('astro:internal-actions'); | ||
|
||
for (const key of pathKeys) { | ||
if (!(key in actionLookup)) { | ||
return undefined; | ||
} | ||
actionLookup = actionLookup[key]; | ||
} | ||
if (typeof actionLookup !== 'function') { | ||
return undefined; | ||
} | ||
return actionLookup; | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the
getActionResult
constructor torender-context
. This ensures only serializable values are sent throughlocals
for edge middleware support. It also simplified our code in the process by removing thatnextLocalsStub
utility!