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

Axios v1 Upgrade: CORS Error Triggered by useCache: true Option #764

Open
adamstankiewicz opened this issue Feb 13, 2025 · 0 comments
Open

Comments

@adamstankiewicz
Copy link
Member

A recent upgrade to axios v1 in frontend-platform caused a CORS error for what appears to be single API call (as far as we have been able to tell) in Enterprise Learner Portal MFE, though it's largely unclear whether it potentially impacts more APIs than this one.

The JavaScript error associated with the failed request suggests the following:

request header field cache-control is not allowed

It was identified that the MFE calling this affected API was using the opt-in useCache: true option, to enable client-side caching on responses to this API for performance optimizations and preventing loading states where possible.

The CORS error was resolved by removing the useCache: true option, which results in the pre-flight OPTIONS request to pass the CORS check and resolve the response successfully.

If running into CORS errors on requests due to the above error, check if you're using useCache: true; if so, the recommendation is to opt out of frontend-platform's client-side caching baked into the axios HTTP client, in favor of relying on other, more widely accepted means of client-side caching (e.g., with @tanstack/react-query).

We may consider adding a deprecation warning when useCache: true is used, as a "use-at-your-own-risk" sort of warning but likely to also mention its eventual deprecation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant