Skip to content

fix(common): skip transfer cache on client #55012

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

Closed

Conversation

Jefftopia
Copy link
Contributor

@Jefftopia Jefftopia commented Mar 23, 2024

transfer cache interceptor should not run again on the client as it is intended for server to client handoff

PR Type

What kind of change does this PR introduce?

  • [ X] 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?

In rare instances, the transfer cache interceptor may execute on the client. While this does not appear to introduce problems, it is an unnecessary step.

Issue Number: #54444

What is the new behavior?

The transfer cache interceptor no longer performs caching behavior in the 'broswer' platform.

Does this PR introduce a breaking change?

  • Yes
  • No

@pullapprove pullapprove bot requested a review from dylhunn March 23, 2024 16:34
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Mar 23, 2024
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

@Jefftopia thanks for creating the PR 👍

I've left a comment and also added @alan-agius4 as a reviewer to take a look at the change.

@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer area: common/http Issues related to HTTP and HTTP Client target: patch This PR is targeted for the next patch release server: http cache labels Mar 23, 2024
@ngbot ngbot bot added this to the Backlog milestone Mar 23, 2024
@AndrewKushnir AndrewKushnir requested review from alan-agius4 and removed request for dylhunn March 23, 2024 20:43
@AndrewKushnir
Copy link
Contributor

@Jefftopia one additional comment: I'd propose to change the commit message (via git commit --amend) from feat(common) -> fix(common) (or perf(common)), this change looks more like a fix or a perf improvement vs a new feature.

@sonukapoor
Copy link
Contributor

Hey @Jefftopia - Welcome :)

@Jefftopia Jefftopia force-pushed the feat/skip-transfer-cache-browser branch from 6f8b48a to 6dad001 Compare March 23, 2024 23:57
@angular-robot angular-robot bot removed the detected: feature PR contains a feature commit label Mar 23, 2024
@Jefftopia Jefftopia force-pushed the feat/skip-transfer-cache-browser branch from 6dad001 to f62f423 Compare March 24, 2024 00:00
@Jefftopia Jefftopia force-pushed the feat/skip-transfer-cache-browser branch from f62f423 to f02f848 Compare March 24, 2024 00:31
@sonukapoor
Copy link
Contributor

@Jefftopia Its usually better to push additional commits up (instead of modifying the existing commit), so that its easier to see the changes from commit to commit.

@Jefftopia
Copy link
Contributor Author

Jefftopia commented Mar 24, 2024

@sonukapoor oh hey 👋

Missed your comment before but I won't squash everything going forward, thanks.

@sonukapoor
Copy link
Contributor

Thanks @Jefftopia Changes LGTM. Lets's wait for Alans input.

Copy link
Contributor

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

On the browser only adding to setting to the cache should be skipped

transferState.set<TransferHttpResponse>(storeKey, {

As the current change will cause the cache not to be used at all which is undesired.

Copy link
Contributor

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

Can you please amend the last 2 commits to use fixup!

IE: fixup! fix(common): skip transfer cache on client

@alan-agius4 alan-agius4 added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Mar 25, 2024
@Jefftopia Jefftopia force-pushed the feat/skip-transfer-cache-browser branch from 42df598 to a8d132a Compare March 25, 2024 21:47
@Jefftopia
Copy link
Contributor Author

done

@AndrewKushnir AndrewKushnir changed the title feat(common): skip transfer cache on client #54444 fix(common): skip transfer cache on client Mar 25, 2024
@AndrewKushnir
Copy link
Contributor

@Jefftopia thanks for updating the PR. It looks like there is still a second commit (with the "Merge branch 'main' of ..." commit message). Could you please rebase and update the branch to have just 1 commit with all changes? Thank you.

@Jefftopia
Copy link
Contributor Author

Jefftopia commented Mar 26, 2024

@Jefftopia thanks for updating the PR. It looks like there is still a second commit (with the "Merge branch 'main' of ..." commit message). Could you please rebase and update the branch to have just 1 commit with all changes? Thank you.

@AndrewKushnir
It's a merge commit. You can't rebase merge commits. They can be squashed onto main and I believe Github provides you the option to do this. Are there guidelines around merge commits? I didn't see them in the developer docs.

Edit: I went ahead and reset then rebased. Oof.

@sonukapoor
Copy link
Contributor

@Jefftopia You could try to drop that commit and rebase again from main.

@Jefftopia Jefftopia force-pushed the feat/skip-transfer-cache-browser branch from 0dbeb44 to 72a23c1 Compare March 26, 2024 02:16
@Jefftopia
Copy link
Contributor Author

@Jefftopia You could try to drop that commit and rebase again from main.

Done.

@sonukapoor
Copy link
Contributor

sonukapoor commented Mar 26, 2024

Nice 👍

I usually use this git command to add a fixup commit: git commit --fixup <COMMIT_ID_OF_FIRST_COMMIT>

Copy link
Contributor

@sonukapoor sonukapoor left a comment

Choose a reason for hiding this comment

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

🎉

@Jefftopia
Copy link
Contributor Author

Nice 👍

I usually use this git command to add a fixup commit: git commit --fixup <COMMIT_ID_OF_FIRST_COMMIT>

@sonukapoor Yes, I used fixup for the commits addressing but you cannot fixup a merge commit ;-) Lesson learned for me -- you can only rebase on another branch to avoid merge commits.

@Jefftopia
Copy link
Contributor Author

Jefftopia commented Mar 26, 2024

@alan-agius4 Thanks for your patience here. After "squashing" my merge commit, hydration specs failed. The PLATFORM_ID token was resolved as an InjectionToken object rather than a string. My latest push uses EnvironmentInjector again which contains the expected value in the hydration tests.

I understand the interceptor has its own injection context but would be curious to know why that is to be preferred over environment injector for PLATFORM_ID in particular @AndrewKushnir

Screen Shot 2024-03-26 at 8 37 44 AM

transfer cache interceptor should not run again on the client as it is intended for server to client handoff
@Jefftopia Jefftopia force-pushed the feat/skip-transfer-cache-browser branch from 222743e to 6285c78 Compare March 27, 2024 01:23
@AndrewKushnir AndrewKushnir removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Mar 27, 2024
TestBed.configureTestingModule({
declarations: [SomeComponent],
providers: [
{provide: PLATFORM_ID, useValue: 'browser'},
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Ideally we should be using PLATFORM_BROWSER_ID instead of the browser string. Same goes for the server string in the cases below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this has not been addressed.

@Jefftopia
Copy link
Contributor Author

Bump

Copy link
Contributor

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

LGTM, although technically the commit scope should be http and not common.

@@ -163,10 +165,12 @@ export function transferCacheInterceptorFn(
);
}

// Request not found in cache. Make the request and cache it.
const isServer = isPlatformServer(inject(PLATFORM_ID));
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: We could use isPlatformBrowser here to avoid the additional symbol. (Couple of less bytes)

@alan-agius4 alan-agius4 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 9, 2024
@atscott
Copy link
Contributor

atscott commented Apr 9, 2024

This PR was merged into the repository by commit 11705f5.

atscott pushed a commit that referenced this pull request Apr 9, 2024
transfer cache interceptor should not run again on the client as it is intended for server to client handoff

PR Close #55012
@atscott atscott closed this in 11705f5 Apr 9, 2024
iteriani pushed a commit to iteriani/angular that referenced this pull request Apr 11, 2024
transfer cache interceptor should not run again on the client as it is intended for server to client handoff

PR Close angular#55012
@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
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 Issues related to HTTP and HTTP Client server: http cache target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants