question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request Deduplication

See original GitHub issue

Core Library

MSAL.js v2 (@azure/msal-browser)

Wrapper Library

Not Applicable

Description

Hi!

I have a React project which uses @azure/msal-browser. When we call our API, we use a custom fetcher that calls acquireTokenSilent before the request. We use the custom fetcher through a library (SWR) that includes fetching hooks with request deduplication etc.

So if I use the fetching hook from the library multiple places to fetch data from the same endpoint, our custom fetcher will only be called once. However, if the hook is used multiple times in the same page, to different endpoints, our custom fetcher gets called multiple times, and therefore also acquireTokenSilent. This results in multiple network calls for configurations and tokens, and often so many that the browser limits other requests.

(I know i can skip the metadata retrieval by manually providing it, but it still happens for tokens)

image image image

I might be implementing the whole thing wrong, and should decouple the token request from the api request in my code. But it would be nice if there was some kind of request deduplication functionality in the package.

Source

External (Customer)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonnuttercommented, Apr 12, 2022

@h3rmanj Thanks. What you observe is currently expected behavior. When you login, the login call will initiate the first call to teh metadata endpoints, which gets cached and reused for the acquireTokenSilent calls. When you are already logged in (after refreshing), the login call doesn’t happen again, and since the two acquireTokenSilent calls happen in parallel, they’ll both make a metadata network call.

As mentioned, we have started working on improvements to how we fetch metadata, which I think will address the concerns here (i.e. by not making the network calls at all in most scenarios). You can follow #4536 to see our progress there.

1reaction
tnorlingcommented, Apr 7, 2022

The metadata call should only be made once per page load per PublicClientApplication instance. Can you make sure you are not reinstantiating PublicClientApplication? When using React you should not instantiate PublicClientApplication inside a React component due to re-renders potentially causing reinstantiation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request Deduplication Pattern: Introduction
The main goal of the request deduplication pattern is to define a mechanism by which we can prevent duplicate requests specifically for ...
Read more >
26 Request deduplication - API Design ... - liveBook · Manning
This chapter covers... How to use request identifiers to prevent duplicate requests in a world of imperfect networks; How to manage collisions with...
Read more >
26 Request deduplication - API Design Patterns [Book]
26 Request deduplication This chapter covers How to use request identifiers to prevent duplicate requests How to manage collisions with request identifiers ...
Read more >
react-request/request-deduplication.md at master
Request Deduplication. React Request will prevent two identical HTTP requests from being in flight at the same time. It does this by comparing...
Read more >
How to understand the request deduplication in SWR
SWR is an amazing react library that makes fetching data easier and more performant. What I really li... Tagged with react, swr, javascript....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found