Avoid duplicate POST on post-submit quiz page reload#4123
Avoid duplicate POST on post-submit quiz page reload#4123lkraav wants to merge 1 commit intoAutomattic:trunkfrom
Conversation
alexsanford
left a comment
There was a problem hiding this comment.
I think this is a good tweak. Just a bit concerned about compatibility (see comment below), but if we can do this without changing the action then let's go for it!
|
|
||
| // Fire the complete quiz button submit for grading action. | ||
| add_action( 'sensei_single_quiz_content_inside_before', array( $this, 'user_quiz_submit_listener' ) ); | ||
| add_action( 'template_redirect', array( $this, 'user_quiz_submit_listener' ) ); |
There was a problem hiding this comment.
Can we do this without changing the action? This would be a breaking change for any customizations that remove or modify these hooks.
There was a problem hiding this comment.
Hm, changing the action to what's better aligned with the callbacks' purpose is sort of the whole point here.. 🤔
There's also prior art right around these add_action calls that use template_redirect, so we also achieve better systemic alignment here.
Breaking change: yes - what is Sensei's policy for versioning? Such is usually handled by new major versions, but I'm aware WP and WC don't follow semver.
It seems like this change is fairly well "updatable" in customizations, if we highlight it well enough in release documentation.
Your thoughts?
There was a problem hiding this comment.
We have this deprecation policy that we try to adhere to, but it doesn't cover changing actions like this 🤔
I was thinking that we might be able to fix the problem (refresh causing quiz submit) without changing the hook, but I agree that moving the functionality out of the rendering actions ultimately makes more sense.
Let me circle back on this.
Changes proposed in this Pull Request
This became a problem when we implemented a quiz re-take delay mechanism.
People would reload quiz page to see how much time remaining to wait, but this re-POSTs quiz and resets our timer.
Solution, and relevant part to Sensei core - proper hygiene in general, is to have a simple pre-output phase GET redirect to quiz URL, that upon reload will not resubmit quiz data.
RATIONALE
Quiz submit should be an intentional operation - page reload should not cause it in the background, since it has implications about "when was quiz last submitted" and potentially other related data (our timer use case), important to online schools, being incorrect.
I don't see any specific usefulness for these callbacks to live on frontend rendering phase hooks. Please enlighten me if I'm missing something.
Testing instructions