Skip to content

feat(http): expose transferStateInterceptorFn in public api#53815

Closed
jsaguet wants to merge 1 commit intoangular:mainfrom
jsaguet:feat/export-transfer-state-interceptor-fn
Closed

feat(http): expose transferStateInterceptorFn in public api#53815
jsaguet wants to merge 1 commit intoangular:mainfrom
jsaguet:feat/export-transfer-state-interceptor-fn

Conversation

@jsaguet
Copy link
Contributor

@jsaguet jsaguet commented Jan 6, 2024

Expose transferStateInterceptorFn in public api so that developers can use it where best suited in the interceptor chain. This is useful when different urls are used to access the same APIs between server and browser. By placing the interceptor before requests urls become different, the cached request can be reused on the client.

Note on usage: provideClientHydration should be called with withNoTransferCache to disable the default cache interceptor which is the last one executed.

Fixes #53702

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?

Currently, it is not possible to use http transfer cache when urls used to access the different APIs differ between calls made from the server and the browser.

This is a common use case when server side rendering happens in a private network in large companies.
It is mainly done to reduce latency, avoiding network proxies and even SSL handshakes when using HTTP in the private network.

Since the transferCacheInterceptorFn is always the last executed interceptor, urls will be different and therefore not reused on the client.

Issue Number: #53702

What is the new behavior?

This PR exposes the transferCacheInterceptorFn in the public API so that developers can provide it manually in provideHttpClient() to be able to solve their specific use cases.

By placing transferCacheInterceptorFnat the right place in the interceptor chain (e.g. before server & browser urls differ), developers can make sure that the requests will be reused on the client during hydration.

The behavior of provideClientHydration() is kept exactly the same (disabling http transfer cache with withNoHttpTransferCache() and using global options with withHttpTransferCacheOptions().

The idea is that good defaults are applied for classic use cases while providing some flexibility for more complex cases.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

I would like for this PR to serve as discussion regarding the best option to solve use cases mentionned in #53702

@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Jan 6, 2024
@jsaguet jsaguet force-pushed the feat/export-transfer-state-interceptor-fn branch from 9993d61 to f2de9e6 Compare January 6, 2024 14:44
@dylhunn dylhunn added the area: common Issues related to APIs in the @angular/common package label Jan 17, 2024
@ngbot ngbot bot added this to the Backlog milestone Jan 17, 2024
@jsaguet jsaguet force-pushed the feat/export-transfer-state-interceptor-fn branch from f2de9e6 to 0eadaea Compare February 2, 2024 16:47
@jsaguet jsaguet force-pushed the feat/export-transfer-state-interceptor-fn branch from 0eadaea to 4f0165f Compare February 24, 2024 17:34
@jsaguet jsaguet force-pushed the feat/export-transfer-state-interceptor-fn branch 2 times, most recently from d815d68 to 0bd25a1 Compare March 16, 2024 09:49
Expose `transferStateInterceptorFn` in public api so that developers can use it where best suited in the interceptor chain.
This is useful when different urls are used to access the same APIs between server and browser. By placing the interceptor before requests urls become different, the cached request can be reused on the client.

Note on usage: `provideClientHydration` should be called with `withNoTransferCache` to disable the default cache interceptor which is the last one executed.
@jsaguet jsaguet force-pushed the feat/export-transfer-state-interceptor-fn branch from 0bd25a1 to b152462 Compare March 16, 2024 09:51
@AndrewKushnir
Copy link
Contributor

Just for context: there is also an alternative proposal described in #53702 (comment).

@jsaguet
Copy link
Contributor Author

jsaguet commented Apr 10, 2024

Closed in favor of #55274

@jsaguet jsaguet closed this Apr 10, 2024
@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 11, 2024
@jsaguet jsaguet deleted the feat/export-transfer-state-interceptor-fn branch May 11, 2024 18:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: common Issues related to APIs in the @angular/common package detected: feature PR contains a feature commit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow caching HTTP requests when urls differ between server and client

3 participants