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

Helper For Feed: XML Error Due To Empty Attribute "data-rocket-preload" #121

Open
realrellek opened this issue Feb 28, 2025 · 2 comments
Open

Comments

@realrellek
Copy link

Describe the bug
The helper handles a feed like a regular HTML page, and thus notes preload attributes. Leaving them empty causes a parse error (on pedantic readers at least), see:
https://feeds.feedburner.com/apfelpage

To Reproduce
Steps to reproduce the behavior:

  1. Install WP Rocket
  2. Install the Feed Helper
  3. Check the feed

Expected behavior
Maybe the helper should prevent changing code in non-html documents.

Screenshots
Image

Desktop (please complete the following information):

  • OS: macOS
  • Browser: Chrome
  • Version 133

Smartphone (please complete the following information):

  • Device: iPhone 16 Pro Max
  • OS: iOS 18.3.1
  • Browser Safari
  • Version Phew, the bundled version

Additional context
We've installed the feed cacher because Claudebot was a little over-ambitious and since feeds were loaded from the database, it put a lot of work on the server. Thus, the feed cacher.

This issue might be slightly related with this one.
#117

@realrellek
Copy link
Author

realrellek commented Mar 1, 2025

Hewwo,

I'm coming back with almost 3 hours of playing around with said plugin. So the issue is that this LCP optimization kicks in.

And from how I got it, this could be prevented by setting the DONOTROCKETOPTIMIZE constant.

I've tried quite a lot of variations on where to put the constant to, because I don't have a feed template in my theme, and frankly, the only reason I would need one, is to prevent WP Rocket from "optimizing" the RSS feed. So the plugin should do it. :)

What I have tried is the following:

in wp-rocket-cache-feed/wp-rocket-cache-feed.php, I've located this line:

add_action( 'plugins_loaded', 'wp_rocket_cache_feed_init' );

and added this below that line:

add_action('template_redirect', 'wp_rocket_cache_feed_but_without_optimization');

function wp_rocket_cache_feed_but_without_optimization() {
        if ( is_feed() ) {
                echo '<!--';
                if ( defined( 'DONOTROCKETOPTIMIZE' ) ) {
                        var_dump( DONOTROCKETOPTIMIZE );
                } else {
                        echo '!! bool(false)'.PHP_EOL;
                        define( 'DONOTROCKETOPTIMIZE', true );
                        var_dump( DONOTROCKETOPTIMIZE );
                }
                echo '-->';

                if ( ! defined( 'DONOTROCKETOPTIMIZE' ) ) {
                        define( 'DONOTROCKETOPTIMIZE', true );
                }
        }
}

The hook template_redirect seemed fitting because this is the point where WordPress has loaded far enough to process the request, so I can safely query if it is a feed. Also, this is before anything is sent to the browser. As far as I understood how WPR works, it tries to just request the site and will take whatever WP outputs to its buffer and create the static file. So again, this hook seems to be suitable for injecting the constant.

Obviously, I have some debug code in my snippet because I wanted to see where we are.

When I am logged in, DONOTROCKETOPTIMIZE is already set to true. In which case no optimizations happen, also not the problematic <link ...> tag.

As a guest, DONOTROCKETOPTIMIZE is unset which WPR considers false. So I set it to true and had myself confirm it's actually true.

This seems to be too late though. While I DO HAVE confirmation as a comment in the cached feed:

<!--!! bool(false)
bool(true)
-->

it still applies the optimizations, and thus the <link tag which breaks the RSS.

Is anyone smarter than me? How can I set DONOTROCKETOPTIMIZE only for feeds in a way that WPR has not yet made its own decision?

Thank you!

@realrellek
Copy link
Author

realrellek commented Mar 3, 2025

Hello, it's me again :)

I am sorry to report I had to disable this plugin. It invalidated the feeds too much, so not only Feedburner has a problem with them, but also other readers, ex. WordPress' very own RSS parser which we use as a sidebar widget. It says:

https://www.apfelrat.de/feed/ is invalid XML, likely due to invalid characters. XML error: Invalid document end at line 197, column 1

Well, there was no line 197, but 196 was a bunch of WPR bacon JS (after </rss>), so I'd think this was the problem.

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

No branches or pull requests

1 participant