Skip to content

Site Editor: Avoid client side redirection in initial load #36873

@Mamaduka

Description

@Mamaduka

Site Editor sets current page context and handles context-based redirection on the client; see URLQueryController. Parts of this logic can be moved on server-side and passed to the editor during initialization.

  • Create a function to generate context on the server. See the basic example below.
  • Handle all context-related global state using a single action/selector, probably based on setPage.
  • Try to find better alternative for __experimentalGetTemplateForLink selector.
Basic Example
function gutneberg_get_page_context() {
	$context = [];
	$id   = isset( $_GET['postId'] ) ? $_GET['postId'] : null;
	$type = isset( $_GET['postType'] ) ? $_GET['postType'] : null;
	$type_obj = get_post_type_object( $type );

	if ( ! $type_obj ) {
		return $context;
	}

	if ( in_array( $type_obj->name, [ 'wp_template', 'wp_template_part' ], true ) ) {
		$template = gutenberg_get_block_template( $id, $type_obj->name );

		if ( ! $template ) {
			return $context;
		}

		return [
			'id'   => $template->id,
			'type' => $template->type,
			'page' => [
				'templateSlug' => $template->slug,
			],
		];
	}
}

Metadata

Metadata

Assignees

Labels

[Feature] Site EditorRelated to the overarching Site Editor (formerly "full site editing")[Status] In ProgressTracking issues with work in progress[Type] EnhancementA suggestion for improvement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions