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(vercel): streaming #8879

Merged
merged 8 commits into from
Nov 7, 2023
Merged

feat(vercel): streaming #8879

merged 8 commits into from
Nov 7, 2023

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Oct 20, 2023

@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2023

🦋 Changeset detected

Latest commit: b05a2ec

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 the pkg: integration Related to any renderer integration (scope) label Oct 20, 2023
@natemoo-re
Copy link
Member

Oh I had no idea we didn't already have this enabled! Seems like it should default to true, yeah?

@lilnasy
Copy link
Contributor Author

lilnasy commented Oct 20, 2023

Yeah, but that's a major change isn't it. I think it could go as minor and opt-in for and we switch the default whenever we feel like releasing a major version.

@natemoo-re
Copy link
Member

Ah yes, didn't consider that. Makes sense!

@github-actions github-actions bot added the pr: docs A PR that includes documentation for review label Oct 30, 2023
@lilnasy lilnasy marked this pull request as ready for review October 30, 2023 16:05
@lilnasy lilnasy marked this pull request as draft October 30, 2023 16:06
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

LGTM! As I mentioned, this would make sense to enabled by default in the next major version of the adapter.

Comment on lines 109 to 110
/** Whether to allow the serverless function to stream the response to the browser. */
streaming?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

I feel like @sarah11918 might have thoughts on the wording here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm hoping lol

Copy link
Member

Choose a reason for hiding this comment

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

I want to see which direction the README takes before bringing that over here! Don't let me forget about this, though!

@lilnasy lilnasy marked this pull request as ready for review October 30, 2023 17:44
**Type:** `boolean`<br>
**Available for:** Serverless

Use this property to set whether the serverless function will stream the response to the browser.
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
Use this property to set whether the serverless function will stream the response to the browser.
Determines whether or not the serverless function will stream its response to the browser, sending components as they are rendered.
The default value is `false`. Set this value to `true` in your Vercel adapter configuration to enable streaming.

I'm assuming the default is false, if you have to set it to be true to take effect? I think it would be good to state that. Maybe something like above?

Also, to check:

  1. In the caution just under here in docs: https://docs.astro.build/en/guides/server-side-rendering/#astrorequestmethod , and a little further down the page in the streaming section, it sounds like streaming is automatically used for SSR / output: 'server'. So at first I was confused to even see this PR! If this is not the case, then do the other docs need updating? Just trying to reconcile what's here vs on the existing SSR page.

  2. That caution I linked to explains that because of streaming, you have to use features that modify the response headers only at the page level and not the component level (because the response headers may already be sent by the time some components render). Should a similar warning exist or be linked to from here re: enabling streaming? Is this a point you think might be important for someone to know, or potentially a breaking change in an existing project if they enable this?

Copy link
Contributor Author

@lilnasy lilnasy Nov 1, 2023

Choose a reason for hiding this comment

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

I'm assuming the default is false

Effectively, yes, but it's not out default, it is Vercel's. So, I'm a bit hesitant to explicitly to document it on our site.

  1. In this case it is the platform that interfered and made it all-at-once. I was not aware that Vercel did this, and neither was Nate. I just stumbled upon a suspicious Vercel reference doc and had to try it out to confirm. We have to explicitly tell Vercel to actually allow streaming.

  2. No, the limitations apply the same no matter what the platform does once Astro is done. And there isn't too much of a breaking concern, just a formality in this case (when we release a major version to make it the default). Everything behaves the same other than the timing of the response parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, the suggestion looks good to me but it does make it inconsistent with descriptions of the other config options in the README.

Copy link
Member

Choose a reason for hiding this comment

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

OK, so thinking about this then! I'm looking back through earlier convo and noticing Nate thought it was true by default.

So, I agree, this actually does sound in keeping with what we expected and documented! No worries about those extra concerns!

Give me a few minutes more to think about updated wording.

Co-authored-by: Sarah Rainsberger <[email protected]>
Comment on lines 289 to 291
Determines whether or not the serverless function will stream its response to the browser, sending components as they are rendered.

The default value is `false`. Set this value to `true` in your Vercel adapter configuration to enable streaming.
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
Determines whether or not the serverless function will stream its response to the browser, sending components as they are rendered.
The default value is `false`. Set this value to `true` in your Vercel adapter configuration to enable streaming.
Use this property to enable Astro's HTML streaming.

I kind of want something like this now, because the docs really do imply this happens by default. (And yes, this seems to be more consistent with the others.)

What do you think about something like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm it won't be limited to HTML. Although the non-HTML cases would be where the user is creating their own streaming responses from scratch.

Copy link
Member

@sarah11918 sarah11918 Nov 1, 2023

Choose a reason for hiding this comment

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

OK, so I'll tell you where my little stumbling blocks are and YOU propose what works! 😄

Grammatically:

  • "the serverless function" sounds jarring out of place. I never like a "the" if we haven't defined something yet. If you can be more descriptive and avoid the implied context of a "the", that would go a long way.

Philosophically:

  • I really don't like that regular docs say that we do HTML streaming and apparently, sometimes we don't! So, I'd be happier from a narrative standpoint if this default were set to true (can we do that? can we build it that way?) and then this configuration turns it OFF. (Note: even if this feature builds the ability to turn it on, maybe that doesn't have to be the way the feature is USED by the user?) Then the story matches the other adapters, and we can say that you CAN turn it off to do x, y, and z if we want to give use cases that are not... just how our stuff is supposed to work? I feel we can get away with being less define-y here in that case, and say you can remove and either not use, roll your own etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, the serverless function is the particular one created when you deploy to Vercel, at least intended to be that one.

So, I'd be happier from a narrative standpoint if this default were set to true

I agree, it's a documented feature. We could probably make a major release to change the default very soon (but not right away), so that streaming is always the case. And I think it is a good idea for another major release after to remove the option altogether.

Then the story matches the other adapters

Netlify never streams either 😶

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we build it that way?
Yes :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is now built that way. Streaming with no configuration to opt-out, just the way it should be.

Copy link
Member

Choose a reason for hiding this comment

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

Netlify never streams either 😶

What even is happening?? The cake is a lie! 😅

So, I don't want anyone's project to break with this change, of course! Aligning this with docs is helpful for me, since that's the story we tell pretty clearly, but if we've been misinformed then we can change on our end, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Breaking is not a concern, just that the change is going to be more visible than what someone might expect from a minor or patch release. So a major release is important more because the user needs to be given notice about what's happening.

@bluwy
Copy link
Member

bluwy commented Nov 6, 2023

Just checking, since this is marked a major, do users have to do something special to handle this change? If not and it would still work as usual, maybe it should be marked a minor instead?

@lilnasy
Copy link
Contributor Author

lilnasy commented Nov 6, 2023

@bluwy Yeah, that is a point of discussion. There's nothing for users to change, but I do think users need to be aware that it is happening, unlike with a patch or minor update. So I'm going with a major to be on the safe side.

@bluwy
Copy link
Member

bluwy commented Nov 6, 2023

If it's only an under-the-hood change, I'd vote going with minors (or even a patch since we had always been streaming but never worked in Vercel). We had made larger internal changes in the past that are released under minor/patch. e.g refactoring the runtime to remove generators, and swapping shiki to shikiji.

@ematipico
Copy link
Member

ematipico commented Nov 6, 2023

We aren't breaking anything, I would avoid a major. No need to alert the users.

Although it seems this is a default now...

I would like to avoid another functionPerRoute to be honest

@lilnasy
Copy link
Contributor Author

lilnasy commented Nov 6, 2023

@ematipico Opt-in to be enabled by default later in a major was the initial approach. Checking in with Matthew, the resolution was that major releases for adapters are not as precious as astro.

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.

Left a suggestion for the changeset!


The Vercel adapter now streams responses!

This brings better performance to your visitors by showing them content as it is rendered. The browser can also start loading the required stylesheets and scripts much sooner, which ultimately results in faster full page loads.
Copy link
Member

@sarah11918 sarah11918 Nov 6, 2023

Choose a reason for hiding this comment

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

Suggested change
This brings better performance to your visitors by showing them content as it is rendered. The browser can also start loading the required stylesheets and scripts much sooner, which ultimately results in faster full page loads.
This brings better performance to your visitors by showing them content as it is rendered. The browser can also start loading the required stylesheets and scripts much sooner, which ultimately results in faster full page loads.
Read more about [HTML streaming](https://docs.astro.build/en/guides/server-side-rendering/#html-streaming) in the Astro docs.

Up to you! Since there are warnings involved with streaming, it couldn't hurt to send to the new docs. BUT, since this doesn't break anything, not really needed anymore. (Was added when I was afraid that enabling this changed the Response headers behaviour)

NOTE: Depending on how quickly this merges, I have a PR that would add the anchor link above but currently the URL is only #streaming. If this is to merge soon, I can pre-emptively update existing docs to that link now, even before the new page is published.

Copy link
Member

Choose a reason for hiding this comment

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

Withdrawing this suggestion! With that docs page about to change, it's maybe a little too disruptive at this exact moment.

@matthewp
Copy link
Contributor

matthewp commented Nov 6, 2023

I'm also comfortable with doing this as a minor if @lilnasy is. I don't have a strong preference, but felt that if it was between a config option or a major, that we might as well just do the major.

@lilnasy
Copy link
Contributor Author

lilnasy commented Nov 6, 2023

Switching to a minor release as there is consensus towards it.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Looks good to me. I think I'm more comfortable with having this major because we are adding a new feature as a default. Technically it should be the same, but we have been so wrong in the past... 😆

I leave the final decision to you @lilnasy ! I trust your gut

@lilnasy
Copy link
Contributor Author

lilnasy commented Nov 6, 2023

I would've been more comfortable with major too. But having tried it out, I don't think there's room for unintended side effects to appear. I think minor works after weighing the paperwork against the feature.

@lilnasy
Copy link
Contributor Author

lilnasy commented Nov 6, 2023

!preview streaming (doesnt work, my branch is on a fork)

@lilnasy lilnasy merged commit 754e4fd into withastro:main Nov 7, 2023
1 check passed
@astrobot-houston astrobot-houston mentioned this pull request Nov 7, 2023
@lilnasy lilnasy deleted the vercel-streaming branch November 12, 2023 01:22
natemoo-re pushed a commit that referenced this pull request Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants