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

Adding attributes to Sensei LMS blocks results in infinite loop during Update #1052

Closed
chvillanuevap opened this issue Aug 16, 2023 · 3 comments
Labels

Comments

@chvillanuevap
Copy link

Description

This is a weird bug and I'm not exactly sure why it is happening. It might be related to WordPress/gutenberg#16850 and #868. Updating a Lesson post from Sensei LMS Pro while Popup Maker is active causes an infinite loop.

Step-by-step reproduction instructions

Steps to reproduce:

  1. Install Sensei LMS Pro (I'm happy to upload a copy of the plugin if needed).
  2. Install the free version of Popup Maker.
  3. Add a new Lesson post.
  4. In the Lesson, add the Quiz block.
  5. Click Publish/Update.

When Popup Maker is not active, the post updates and everything is fine. However, when Popup Maker is active, the Update button gets caught in an infinite loop. See GIF below:

Screen Recording 2023-08-15 at 10 53 25 PM

I dequeued every single Popup Maker script and the issue persisted. I removed the Popup Control panel and it made no difference. What finally worked was a combined PHP + JS approach, where I commented out the PUM_Admin_BlockEditor::add_attributes_to_registered_blocks method and used the pum_block_editor_popup_trigger_excluded_blocks filter to remove all Sensei LMS blocks. I'm still not sure why it's happening as my experience with Gutenberg is limited. However, it might be a good idea to add the pum_block_editor_popup_trigger_excluded_blocks filter to the PUM_Admin_BlockEditor::add_attributes_to_registered_blocks method as well.

Environment info

WordPress version: 6.3
PHP version: 7.4.30 (also tested on 8.1.9)
Popup Maker version: 1.18.2
Sensei LMS Pro version: 4.16.1

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated.

Yes

@chvillanuevap
Copy link
Author

For now my patch is to remove the Sensei blocks from the function calls.

add_filter( 'pum_block_editor_popup_trigger_excluded_blocks', 'courier_remove_popup_trigger' );

function courier_remove_popup_trigger( array $excluded_blocks ) : array {

	$excluded_blocks[] = 'sensei-lms/quiz';
	$excluded_blocks[] = 'sensei-lms/lesson-actions';
	$excluded_blocks[] = 'sensei-lms/button-view-quiz';
	$excluded_blocks[] = 'sensei-lms/quiz-question';
	$excluded_blocks[] = 'sensei-lms/quiz-question-feedback-correct';
	$excluded_blocks[] = 'sensei-lms/question-answers';
	$excluded_blocks[] = 'sensei-lms/question-description';

	return $excluded_blocks;

}

add_action( 'wp_loaded', 'courier_add_attributes_to_registered_blocks', PHP_INT_MAX );

function courier_add_attributes_to_registered_blocks() : void {

	global $wp_version;

	if ( version_compare( $wp_version, '5.0' ) === -1 ) {
		return;
	}

	$registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();

	foreach ( $registered_blocks as $block ) {

		$has_sensei_block = str_contains( $block->name, 'sensei-lms' ) || str_contains( $block->name, 'sensei-pro' );

		if ( $has_sensei_block ) {
			unset( $block->attributes['openPopupId'] );
		}

	}

}

@chvillanuevap
Copy link
Author

I'm closing this issue. It seems the problem lies with Sensei LMS. Any plugin that inserts a panel to deal with attributes causes the infinite loop.

@danieliser
Copy link
Member

Thanks for letting us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants