WordPress.org

Make WordPress Core

Opened 8 months ago

Last modified 4 months ago

#46379 new defect (bug)

REST API posts/pages response to include scripts needed for display of post content

Reported by: mnelson4 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: REST API Keywords:
Focuses: Cc:
PR Number:

Description

Often post body is dependent on external scripts and stylesheets in order to be displayed correctly, but there is no way to discover what those scripts/stylesheets are.
This problem was encountered in Gutenberg on https://github.com/WordPress/gutenberg/pull/9734, and the fix was to filter the REST API response to include the list of scripts.

You can't know what the scripts are required ahead of time, especially if the API client code is being run from a different server. Shortcodes and Gutenberg blocks can dynamically add scripts and stylesheets.

So, I think the problem is three-fold:

  1. How to detect what scripts/stylesheets are required to display a particular page/post body
  2. How to return that information over the REST API
  3. How can API clients (like the backbone client) use that to display the post's body correctly (with the required javascript/stylesheets)

Change History (4)

#1 @desrosj
8 months ago

  • Milestone changed from Awaiting Review to Future Release

#2 @mnelson4
8 months ago

Oh, also some context on an application: I have a plugin that loads a ton of posts via the REST API and dumps their post bodies into the page. But posts with shortcodes often don't appear correctly because they enqueue javascript which is never returned over the REST API. See https://github.com/mnelson4/printmyblog/issues/9

#3 @mnelson4
8 months ago

I suspect I'll first need to create a feature plugin that attempts to fix this, but ideally a fix will eventually land in core. I've mostly created this in case anyone has great suggestions.

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


4 months ago

Note: See TracTickets for help on using tickets.