doublesecretagency / craft-upvote

Upvote plugin for Craft CMS
Other
16 stars 6 forks source link

Could not determine whether Upvote should be preloaded: null #19

Closed LouisCuvelier closed 4 years ago

LouisCuvelier commented 4 years ago

I've got this errors in the browser console on page loading using Upvote with Blitz plugin.

POST https://website.com/index.php?p=actions/upvote/page/preload 400
Could not determine whether Upvote should be preloaded: null

Any idea to solve this ?

lindseydiloreto commented 4 years ago

Hi Louis,

That's a pretty generic "something went wrong doing AJAX" error. Do you know if you were doing anything unusual at the time?

I have a very hazy and distant memory... were you forcing a trailing slash onto all URLs of your website? If so, that could be causing the problem.

LouisCuvelier commented 4 years ago

Yes, exactly, trailing slash everywhere 😅 You're certainly right and it might be related to this one. But, I'm on Nginx now. I will try later this week to solve this.

Edit : The error just disappeared 🤷‍♂️

lindseydiloreto commented 4 years ago

Ha, perfect! In that case, I'm going to say that the solution is the same...

https://github.com/doublesecretagency/craft-starratings/issues/8#issuecomment-462994020

You are obviously trying to whitelist a different endpoint, but the principle is the same as the Star Ratings issue. 🙂

If you try that solution and it doesn't work, we can reopen this thread.

LouisCuvelier commented 4 years ago

Ok @lindseydiloreto, after digging a little bit more, it's not a Nginx config issue.

On my staging website, I've got the exact same config and it works. The only difference, is that Blitz caching is disabled.

If I refresh all the cache with Blitz, on the prod website, It's working great again. Definitely, something is messing up with Blitz

LouisCuvelier commented 4 years ago

Hey @lindseydiloreto, can you reopen the issue please ?

lindseydiloreto commented 4 years ago

Hi @LouisCuvelier, what changed? Did you try the solution outlined here?

If you are confident that Blitz is the source of the problem, perhaps an issue should be filed over there instead.

LouisCuvelier commented 4 years ago

Hi @lindseydiloreto,

It's not a route issue with a trailing slash. Here's the logged error.

[error][yii\web\HttpException:400] yii\web\BadRequestHttpException: Can not verify your data submission. in /.../vendor/yiisoft/yii2/web/Controller.php:190
Stack trace:
#0 /.../vendor/craftcms/cms/src/web/Controller.php(134): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
#1 /.../vendor/yiisoft/yii2/base/Controller.php(155): craft\web\Controller->beforeAction(Object(yii\base\InlineAction))
#2 /.../vendor/craftcms/cms/src/web/Controller.php(178): yii\base\Controller->runAction('preload', Array)
#3 /.../vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('preload', Array)
#4 /.../vendor/craftcms/cms/src/web/Application.php(291): yii\base\Module->runAction('upvote/page/pre...', Array)
#5 /.../vendor/craftcms/cms/src/web/Application.php(559): craft\web\Application->runAction('upvote/page/pre...', Array)
#6 /.../vendor/craftcms/cms/src/web/Application.php(270): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#7 /.../vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#8 /.../web/index.php(21): yii\base\Application->run()
#9 {main}

It reminds me this. But, I've followed what you said on your doc :

If you are using Blitz, you can stop reading right here! You don't need to do anything mentioned below, Blitz + Upvote will "just work" automagically!

So what do you think ?

lindseydiloreto commented 4 years ago

Hi Louis,

I highly suspect that this is a server configuration issue, and not a bug in the plugin.

If you're convinced that it's an issue with the Upvote plugin, DM me (@lindseydiloreto) on Craft Discord and we can try to walk through it together.

lindseydiloreto commented 4 years ago

Just to close out this thread for good...

This turned out to be a Cloudflare issue, where it was caching a CSRF token that it shouldn't have been. You and Ben Croker largely worked through it without me, so feel free to add additional details if you'd like @LouisCuvelier.

There were no related bugs in Upvote. 👍

LouisCuvelier commented 4 years ago

Explanation : A page rule in Cloudflare was set to "Cache everything" and "Edge Cache TTL : 1 month" But as Cloudflare says in their doc :

Cache Everything - Treats all content as static and caches all file types beyond the Cloudflare default cached content. Respects cache headers from the origin web server unless Edge Cache TTL is also set in the Page Rule. When combined with an Edge Cache TTL > 0, Cache Everything removes cookies from the origin web server response.

So Cloudflare was no longer respecting headers from the origin web server and was caching Craft CMS actions.

Solution : Remove Edge Cache TTL from the page rule.

bencroker commented 4 years ago

FWIW I'm still seeing Cloudflare produce HITs for action requests every now and then, but I can't explain why...

LouisCuvelier commented 4 years ago

Have you purge all website’s cache on Cloudflare ?

bencroker commented 4 years ago

Yes, and that solves the issue, until it spontaneously returns again. Example: https://putyourlightson.com/index.php?p=actions/sprig/components/render&sprig%3Atemplate=35924995ee264c07bd87236ae487f14bfba8a0fef7926d145684eead55268c56sprig-cookbook%2F_components%2Fpagination&page=2