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

Fix for infinite loops in post.excerpt in specific cases #2972

Merged
merged 4 commits into from May 14, 2024

Conversation

Levdbas
Copy link
Member

@Levdbas Levdbas commented Apr 20, 2024

Related:

Issue

When you render a post preview in a dynamic block this will cause an infinite loop.

Solution

When fetching the content from the excerpt method, run the excerpt_remove_blocks function inside the content() method.

Impact

Post previews will probably render faster since now we are not parsing blocks anymore.

Usage Changes

I added a third parameter to the content() method but this is optional.

Considerations

Nothing I can think about right now.

Testing

Test and additional assets added to register a block, render the block via a render callback and then run a post.preview inside it. if you remove the suggested changes in Post.php and run the test it will cause a timeout which shows up in PHPunit as a segmentation fault.

@Levdbas Levdbas linked an issue Apr 20, 2024 that may be closed by this pull request
src/Post.php Outdated Show resolved Hide resolved
@Levdbas
Copy link
Member Author

Levdbas commented Apr 26, 2024

@gchtr , I reverted the parameters to the old ones.

Copy link
Member

@gchtr gchtr left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍.

I’m not a huge fan of adding the $remove_blocks flag as an additional parameter, though. But I can’t think of anything better at the moment.

@nlemoine Anything to add here?

@Levdbas
Copy link
Member Author

Levdbas commented Apr 26, 2024

This looks good to me 👍.

I’m not a huge fan of adding the $remove_blocks flag as an additional parameter, though. But I can’t think of anything better at the moment.

@nlemoine Anything to add here?

I had the same feeling, Ideally you would want to know what the caller is of the content method is, so you can apply the remove block logic that way. But no idea how to solve that. Duplication the content method is also not the way to go in my opinion.

@nlemoine
Copy link
Member

But no idea how to solve that

Using debug_backtrace() ;)

Sorry, I didn't dig that topic much, I trust you guys on this 👍

@Levdbas Levdbas added this to the 2.2.0 milestone May 3, 2024
@Levdbas Levdbas merged commit d064336 into 2.x May 14, 2024
27 of 28 checks passed
@Levdbas Levdbas deleted the 2041-postpreview-causes-infinite-loops branch May 14, 2024 08:21
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.

post.preview causes infinite loops
3 participants