-
Notifications
You must be signed in to change notification settings - Fork 178
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
Media: Remove manual cache busting #4312
Comments
Related: Gutenberg uses the concept of |
Just for the reference of my findings:
So looks like you want to remove this
If both the assumptions are correct, I can only think of one possible solution for now. With the proposed changes for API calls in #8966, all the What if we add one more parameter of Something like this window.webStoriesEditorSettings.preloadAPIResponse = {
'/web-stories/v1/web-story/5/?_embed=..': {},
'/web-stories/v1/media..': {},
'/web-stories/v1/users/?per_page=100..': {}
...
} and then we create some helper function as our own little middleware/HOF of these callbacks in actions.getMedia = useCallback(
({ apiPath, mediaType, searchTerm, pagingNum }) =>
withInitialPreload( apiPath )( () => getMedia({ mediaType, searchTerm, pagingNum }, media) ) ,
[media, getMedia]
);
|
I just had another look at this and it turns out this was fixed in Gutenberg a while ago! 🎉 See:
Preloading now only works a single time, the cache is invalidated after that. That means we no longer need this |
I suppose we still need to keep this for WP < 5.7, which is where this fix was included (Gutenberg 9.1 maps to WP 5.7) |
As we are not going to support 5.7- soon, do we still need this ticket? |
Well, we need the ticket to finally remove this code. We've added this manual cache busting in the past because we had to support older WordPress versions. Now that we are bumping the WP version requirement to WP 5.7+ we should be able to finally remove this manual cache busting, which is why I moved this to Ready for Sprint. Relevant code sections: web-stories-wp/packages/story-editor/src/app/media/local/useContextValueProvider.js Line 190 in 8acb78a
web-stories-wp/packages/story-editor/src/app/media/local/useContextValueProvider.js Line 95 in 8acb78a
web-stories-wp/packages/story-editor/src/app/media/local/useContextValueProvider.js Line 110 in 8acb78a
web-stories-wp/packages/story-editor/src/app/media/local/useContextValueProvider.js Line 190 in 8acb78a
web-stories-wp/packages/story-editor/src/app/media/local/test/useContextValueProvider.js Lines 201 to 256 in 8acb78a
web-stories-wp/packages/wp-story-editor/src/api/media.js Lines 32 to 60 in 8acb78a
web-stories-wp/packages/wp-story-editor/src/api/test/media.js Lines 42 to 64 in 8acb78a
|
Tested using PR #11759. Dragged and dropped one and multiple files, uploaded one and multiple files. No refresh needed to have files displayed in the media gallery. |
Task Description
In the editor we currently preload media items using the
wp.apiFetch
preloading middleware.It is basically works as a cache that can’t be invalidated.
So if
/path/to/load/media
is preloaded, it's not possible to request/path/to/load/media
again to fetch new data as it will always use the cached data.This causes issues like #4109 and requires solutions like #4310.
One possible alternative solution mentioned by @Jhtin is to make the initial call look different from the subsequent calls. Then you preload the first call that looks different and then every subsequent call isn’t cached. Basically the opposite of what #4310 dos.
Essentially, what we need is a way to pre-populate media state upon page load, ideally one that is not so tightly coupled to WordPress, i.e. avoiding
wp.apiFetch
preloading middlewareThe text was updated successfully, but these errors were encountered: