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

fix(http): ensure new cache state is returned on each request #49749

Closed

Conversation

brandonroberts
Copy link
Contributor

@brandonroberts brandonroberts commented Apr 7, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

The cache state is only used only the first server request. Restarting the server uses the cache on the first request.

Subsequent requests skip the cache because the CACHE_STATE object is mutated.

What is the new behavior?

A new cache state is returned on every server request.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Angular v16.0.0-next.7 release with Universal installed and client hydration enabled
Reproduction: https://github.com/brandonroberts/angular-v16-universal-standalone

  1. Clone the repo, install the dependencies
  2. Run npm run dev:ssr
  3. Visit the /todos route
  4. Notice the API request is not made
  5. Reload the page
  6. Notice the API request is made on the client

The cache state is only used only the first server request. Restarting the server uses the cache on first request.

Subsequent requests skip the cache because the value is mutated.

This change ensures a new cache state is returned on every request.
@pullapprove pullapprove bot requested a review from jessicajaniuk April 7, 2023 20:40
@ngbot ngbot bot added this to the Backlog milestone Apr 7, 2023
@jessicajaniuk jessicajaniuk added target: rc This PR is targeted for the next release-candidate action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 7, 2023
@jessicajaniuk jessicajaniuk requested review from alan-agius4 and removed request for jessicajaniuk April 7, 2023 21:40
@pullapprove pullapprove bot requested a review from jessicajaniuk April 7, 2023 21:40
@AndrewKushnir
Copy link
Contributor

@brandonroberts thanks for reporting the issue and submitting a fix! We'll review it asap.

I'm wondering if you could help to put together a test that reproduces the problem, which would also help to ensure that there are no regressions in the future? This might be a good place for a test and it should contain the necessary helpers: https://github.com/angular/angular/blob/main/packages/platform-server/test/integration_spec.ts#L1097.

Thank you.

@brandonroberts
Copy link
Contributor Author

Thanks @AndrewKushnir! Thanks for pointing me to the integration tests also. I wasn't sure where to start on that with it being an internal token.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 11, 2023
@ngbot
Copy link

ngbot bot commented Apr 11, 2023

I see that you just added the action: merge label, but the following checks are still failing:
    failure status "ci/angular: size" is failing
    pending status "mergeability" is pending
    pending status "pullapprove" is pending
    pending 1 pending code review

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken main, please try rebasing to main and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@AndrewKushnir AndrewKushnir added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Apr 11, 2023
@AndrewKushnir AndrewKushnir removed the request for review from jessicajaniuk April 11, 2023 17:37
@AndrewKushnir
Copy link
Contributor

@brandonroberts thanks again for the fix! We will proceed with the merge and we plan to expand the test coverage as a followup (in conjunction with other changes).

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 0b3677e.

AndrewKushnir pushed a commit that referenced this pull request Apr 11, 2023
The cache state is only used only the first server request. Restarting the server uses the cache on first request.

Subsequent requests skip the cache because the value is mutated.

This change ensures a new cache state is returned on every request.

PR Close #49749
@brandonroberts
Copy link
Contributor Author

Thanks @AndrewKushnir and @alan-agius4!

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: common/http merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants