- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 11.4k
 
feat: remove synchronous document.cookie api to avoid jank; use cooki… #7040
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
base: v1.x
Are you sure you want to change the base?
feat: remove synchronous document.cookie api to avoid jank; use cooki… #7040
Conversation
d3cd889    to
    9f794da      
    Compare
  
    | 
           @jasonsaayman Hi, could you feel free to help review this pr? I have ran tests and lints and passed.  | 
    
a982f5b    to
    73d4f8f      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modernizes axios's cookie handling by replacing the synchronous document.cookie API with the asynchronous cookieStore API to eliminate jank issues. The implementation includes fallback support for browsers without cookieStore support.
- Converts cookie operations (read, write, remove) from synchronous to asynchronous
 - Updates resolveConfig function to handle async cookie reading for XSRF tokens
 - Modifies XHR and fetch adapters to properly handle the async configuration resolution
 
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description | 
|---|---|
| lib/helpers/cookies.js | Implements cookieStore API with document.cookie fallback | 
| lib/helpers/resolveConfig.js | Updates XSRF token reading to be async | 
| lib/adapters/xhr.js | Wraps resolveConfig call in Promise chain | 
| lib/adapters/fetch.js | Adds await to resolveConfig call | 
| test/specs/helpers/cookies.spec.js | Updates tests to handle async cookie operations | 
| test/specs/requests.spec.js | Modifies timeout tests and adds cookieStore mocking | 
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| 
           please can you rebase based on the changes in #7129  | 
    
5079539    to
    3997555      
    Compare
  
    | 
           @jasonsaayman Already rebased. Please review again.  | 
    
| 
           @jasonsaayman Please feel free to review and merge. We need to use new axios npm package to avoid jank in PC client. And I want to know the date next version 1.12.3 release. Thanks for maintaining this greate project!  | 
    
| 
           Unfortunately, we have a problem here, as this will introduce a hidden regression for #2609. This is why we avoided implementing features that require an asynchronous API before requesting with the underlying transport within v0.x and v1.x as we shouldn't introduce a breaking change within the major version. The regression isn't that severe, but I'm not sure if we should break the rules to land this in 1.x  | 
    
| 
           @DigitalBrainJS But I found "lib/adapters/fetch.js" use promise to resolveBodyLength before requesting with the underlying transport too.  | 
    
| 
           Yes, because at the time of the first 1.x release, the tests only covered the XHR adapter. There are three possible ways out: 
  | 
    
4ca73c6    to
    112801a      
    Compare
  
    | 
           @DigitalBrainJS Hi, I have done option 2. Using a optional config to get resolveConfig in asynchronous way. Please feel free to review again. Thanks!  | 
    
… API to get resolveConfigs
112801a    to
    373c315      
    Compare
  
    | 
           Tests all passed.  | 
    
We encountered a major source of jank because axios uses the synchronous API
document.cookie(see whatwg/html#11658). Currently, the asynchronous API CookieStore serves as an alternative, so I create this to contribute to axios.