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

Fix preloading middleware referencing stale data for OPTIONS requests #35527

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions packages/api-fetch/src/middlewares/preloading.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function createPreloadingMiddleware( preloadedData ) {
if ( 'GET' === method && cache[ path ] ) {
const cacheData = cache[ path ];

// Unsetting the cache key ensures that the data is only preloaded a single time
// Unsetting the cache key ensures that the data is only used a single time
delete cache[ path ];

return Promise.resolve(
Expand All @@ -72,11 +72,12 @@ function createPreloadingMiddleware( preloadedData ) {
cache[ method ] &&
cache[ method ][ path ]
) {
return Promise.resolve(
parse
? cache[ method ][ path ].body
: cache[ method ][ path ]
);
const cacheData = cache[ method ][ path ];

// Unsetting the cache key ensures that the data is only used a single time
delete cache[ method ][ path ];

return Promise.resolve( parse ? cacheData.body : cacheData );
}
}

Expand Down