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

Improve script loading when streaming is enabled #31338

Closed
shuding opened this issue Nov 12, 2021 · 1 comment
Closed

Improve script loading when streaming is enabled #31338

shuding opened this issue Nov 12, 2021 · 1 comment
Assignees

Comments

@shuding
Copy link
Member

shuding commented Nov 12, 2021

Describe the feature you'd like to request

A while ago we changed the default script loading strategy to use defer in #24939. However this doesn’t work well within the streaming model since deferred scripts will only be executed after finishing the full HTML. This makes selective hydration kinda useless because there is no way to hydrate early.

Describe the solution you'd like

That said, it would be great to switch back to the async strategy for the runtime and modules when concurrentFeatures is enabled, and leverage the bootstrapScripts option (facebook/react#22594) to inject them at the right time.

And finally, a <link rel=preload> tag might also be necessary to maximize performance.

Describe alternatives you've considered

As a workaround, you can also use the disableOptimizedLoading flag to manually switch back to the async strategy. But it can’t start hydration with the perfect timing.

@shuding shuding self-assigned this Dec 10, 2021
kodiakhq bot pushed a commit that referenced this issue Dec 13, 2021
This PR implements the basic inline embedded server response data (#30994) for RSC, as well as partial hydration (#31338) for RSC and React 18 SSR streaming.

For #30994, `renderTargetSuffix` is passed to the `bodyResult` resolver so the stream can inject corresponding hydration scripts and the closing body tag at the correct time. The expected behavior should be _prefix_, _body shell_, _suffix scripts_, _stream and inlined data_, _close body_.

For #31338, we have to force turn on `disableOptimizedLoading` when `concurrentFeatures` is enabled to opt-out of deferred script tags.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
@shuding shuding closed this as completed Dec 13, 2021
cdierkens pushed a commit to cdierkens/next.js that referenced this issue Dec 20, 2021
This PR implements the basic inline embedded server response data (vercel#30994) for RSC, as well as partial hydration (vercel#31338) for RSC and React 18 SSR streaming.

For vercel#30994, `renderTargetSuffix` is passed to the `bodyResult` resolver so the stream can inject corresponding hydration scripts and the closing body tag at the correct time. The expected behavior should be _prefix_, _body shell_, _suffix scripts_, _stream and inlined data_, _close body_.

For vercel#31338, we have to force turn on `disableOptimizedLoading` when `concurrentFeatures` is enabled to opt-out of deferred script tags.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants