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

Refactor endpoint response object handling #7588

Closed
wants to merge 3 commits into from

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jul 6, 2023

Changes

  • Make callEndpoint return a response directly, even converting simple object form to a response so we don't duplicate work.
  • For SSG build, we still need to return the object form. callEndpoint now accepts an extra returnObjectFormIfAvailable param to return that. Mostly for compat as we might remove object form support in Astro 3.0

Testing

Existing tests should pass.

Docs

n/a. internal refactor.

@changeset-bot
Copy link

changeset-bot bot commented Jul 6, 2023

⚠️ No Changeset found

Latest commit: 5debbc7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 6, 2023
Copy link
Member Author

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Note: it's easier to review with whitespaces off. Toggle the comments below for extra context.

Also marking this draft as it's breaking something.

packages/astro/src/core/endpoint/index.ts Show resolved Hide resolved
packages/astro/src/core/endpoint/index.ts Outdated Show resolved Hide resolved
@bluwy bluwy marked this pull request as draft July 6, 2023 15:45
@bluwy
Copy link
Member Author

bluwy commented Jul 7, 2023

Well this didn't really go well. Looks like in dev and prod, we handle simple objects with encoding differently.

Dev: Use Node's Buffer.from
Prod: Use TextEncoder (only works with utf8 strings)

Dev behaviour encompasses prod behaviour, which is fine because it covers static mode that writes the content to a file with different encodings. I don't think this is a nice refactor until if we decide to remove the simple object syntax. Will comment on that linear issue instead.

@bluwy bluwy closed this Jul 7, 2023
@bluwy bluwy deleted the refactor-endpoint-response-handling branch March 18, 2024 09:48
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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant