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

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

Closed
Mamaduka opened this issue Nov 25, 2021 · 0 comments · Fixed by #38817
Closed

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

Mamaduka opened this issue Nov 25, 2021 · 0 comments · Fixed by #38817
Assignees
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@Mamaduka
Copy link
Member

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,
			],
		];
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant