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

Pre-load REST API index data to avoid FOMD #6434

Merged
merged 1 commit into from May 2, 2018
Merged

Pre-load REST API index data to avoid FOMD #6434

merged 1 commit into from May 2, 2018

Conversation

danielbachhuber
Copy link
Member

Because theme_supports data present in the index is used in rendering
UI, it'd be better to include it in the initial payload, instead of
incurring a second API request.

FOMD = Flash of Missing Data

Previously #6318 (comment)

Because `theme_supports` data present in the index is used in rendering
UI, it'd be better to include it in the initial payload, instead of
incurring a second API request.

FOMD = Flash of Missing Data
@danielbachhuber danielbachhuber requested a review from a team April 25, 2018 22:42
@danielbachhuber danielbachhuber added this to the 2.8 milestone Apr 25, 2018
@pento
Copy link
Member

pento commented Apr 26, 2018

It seems like this causes the schema to be loaded twice: can the current schema usage be reworked to use the data preloaded from / as the source?

@danielbachhuber
Copy link
Member Author

It seems like this causes the schema to be loaded twice: can the current schema usage be reworked to use the data preloaded from / as the source?

I'm not sure I follow. Can you clarify?

@aduth
Copy link
Member

aduth commented Apr 26, 2018

I noticed this in #6301, but I thought it was reasonable for this to be loaded asynchronously, particularly because we're doing a union with the current post's format (known/visible/selected at load-time)†.

I don't have a strong opposition to preloading it, though it speaks to a broader question of whether there's a line to be drawn for what should and shouldn't be preloaded. Or preload all the things?

Only discussing current post formats usage. Other future usage could be more disruptive without preloading.

@danielbachhuber
Copy link
Member Author

though it speaks to a broader question of whether there's a line to be drawn for what should and shouldn't be preloaded. Or preload all the things?

I'd think it would be of benefit to preload all data that will be present in the view. The data is going to be fetched anyway, and this would reduce the real-world overhead (which is loading WordPress again and again to serve API requests).

@pento
Copy link
Member

pento commented Apr 27, 2018

In gutenberg_extend_wp_api_backbone_client(), we cache the result of / in wpApiSettings.schema already.

To reproduce, load Gutenberg, View Source, and search for theme_supports.

@danielbachhuber
Copy link
Member Author

In gutenberg_extend_wp_api_backbone_client(), we cache the result of / in wpApiSettings.schema already.

Ah, but then we'd need to get this data into the store. Or, we could reference the global variable. The former seems much more desirable to the latter.

Any opinions on how to reconcile this difference?

@pento
Copy link
Member

pento commented Apr 30, 2018

The schema data is only used here, that I'm aware of, so it should just be a case of loading it from the _wpAPIDataPreload global, instead. If you want to avoid referencing the global directly, then the cache export may be an option, or send a fake request to getCachedResponse().

@danielbachhuber
Copy link
Member Author

@pento Given the uncertainty around a better approach, can we land this and then open an issue to improve upon it in the future?

Copy link
Member

@pento pento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's go with this for now.

@danielbachhuber: Could you please open a new issue to track the problem of / being loaded twice?

@pento pento merged commit f3f59d2 into master May 2, 2018
@pento pento deleted the pre-load-index branch May 2, 2018 00:41
@danielbachhuber
Copy link
Member Author

Could you please open a new issue to track the problem of / being loaded twice?

Yep #6539

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

Successfully merging this pull request may close these issues.

None yet

3 participants