-
-
Notifications
You must be signed in to change notification settings - Fork 202
Automatically set the ajax_load request parameter. #4169
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
base: master
Are you sure you want to change the base?
Conversation
@thet thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment:
To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
@jenkins-plone-org please run jobs |
0117afa
to
180b112
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine to me.
If I see it correctly, the related PRs could each be tested and merged separately (once any comments there are addressed). That makes it easier to test this one as well.
@jenkins-plone-org please run jobs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have the wrong understanding of where X-Requested-With comes from.
Aside from that, this looks okay as long as there's never a case where jquery is making a request where the entire page html is actually needed. (But in that case, there's at least the workaround of passing ?ajax_load=0)
@davisagli Thanks for the answer - I felt I was missing out something you might know :) Right, I see, that The That will already cover most cases. And if a AJAX request is done without this header, nothing will break - only the whole page rendered. And yes, if needed this behavior can explicitly be turned off with |
(Side note: when you force-push a squashed commit, it makes it hard to see what changed compared to previous commits that I already reviewed. I'd rather you add new commits until the PR is done, and then use the "squash and merge" button to merge it as a single commit.) Edited to add: I see github provides a "compare" button to see the changes, so maybe this is just a personal preference thing. |
Here some more info on
|
See my comments on the sister PR #4188 (comment) I am not blocking this, but IMO this is too indirect and potentially will make it hard to debug what is happening. Keep also in mind that subscribers are also hard to override. I would very much prefer to have the check for "is ajax loaded" into a view method. |
@thet I just saw the change in plone/plonetheme.barceloneta#404 to stop applying Diazo theming if ajax_load is true. This doesn't seem safe to me. It could result in different markup if the html for a page is loaded entirely, and then part of the page is replaced to update it by making the same request via an ajax request.
This sounds like a good idea to me. |
Disabling Diazo for any AJAX request was really the intention. That is what I would expect - lean and fast responses for AJAX with all the information I need and without the overhead of Diazo and a full-blown main template. In my opinion Diazo should not be needed for AJAX requests, and for the edge cases where it is needed there is always But I could be wrong with my "anyone wants to disable diazo for ajax" assumption here :) With this PR we have the same situation also for the main template. Before the Regarding the Maybe I should set it even earlier, like in a subscriber for But if this auto-set feature seems to be too dangerous - which I disagree with - I see these options:
I'd love to hear the opinion of other Classic UI people doing a lot of frontend stuff. /cc @MrTango @petschki @pbauer |
Most JavaScript libraries send the "HTTP_X_REQUESTED_WITH" request header set to "XMLHttpRequest" for AJAX requests. For AJAX requests we set the "ajax_load" parameter on the request object before traversing, if it was not already set. This is further used to switch to the ajax_main_template and to turn off Diazo transformations. For AJAX requests which need a full-page rendering this automatic setting can be turned off by adding `?ajax_load=0` as query string to the URL.
Update: Updated for latest changes from #4196 |
@jenkins-plone-org please run jobs |
Set ajax_load parameter even earlier at the ZPublisher.interfaces.IPubStart event.
@jenkins-plone-org please run jobs |
IMO it is the opposite, you should not set it. As explained earlier:
Then you do something. My proposal is to strip down that approach to:
Then you do something. I also think that you should do that in a Plone classic only package.
I do not see any danger at all, it just seems to me too cumbersome to do this 3-steps process when you can do that in one step only. |
@thet I definitely understand the desire to avoid rendering the entire main_template for AJAX requests. And then I can see that it becomes necessary to disable Diazo, because the Diazo rules are probably expecting the full page structure from main_template. But my concern is that since the markup may not be the same if Diazo rules are not applied, then some CSS or Javascript may not find the classes or ids that it is looking for. This is probably not a big problem in the Barceloneta theme, since it makes minimal changes to the unthemed markup. So maybe the change is okay there. And I definitely won't block this myself, since I am not usually working with Classic UI sites these days. But I wanted to explain my concern. |
@davisagli tnx. I understand these concerns and this discussion made me rethink this PR myself. I think the safest option would be to make this optional, with the default turned off. I tried yesterday to make this configurable, but I cannot get the reqistry via Even when I really thought I need/want to set this request parameter as early as possible technical limitations draw me towards the browser view approach, @ale-rt already suggested :) Or an add-on. Not sure what is a better fit. |
@thet Ok, I feel better about it if it is off by default. |
Get "plone.ajax_marker" registry parameter to enable/disable automatic ajax marking. The "ajax_marker" configuration option is defined in "plone.base.interfaces.controlpanel.ISiteSchema" and defaults to "False", so no automatic setting.
…ry can be retrieved but its already too late in the chain and the non-ajax main template was alreday instantiated.
Use the ajax main template if: - ajax_load translate to True - or if we have an xhr request and plone.use_ajax (TBD) is set to True. Don't use the ajax main template if ajax_load is set to a falsy value or we're not in an xhr request.
@ale-rt I understand now what you mean by checking the request, fiddling with it and checking it again. This was a very valuable discussion for me - thanks @ale-rt and @davisagli! The last iteration of this code benefited from it and is IMO really much better (it's not ready yet). My premise was to set For the Diazo part, I plan to do something similar - creating a config option to automatically disable it for AJAX requests to save processing power and save from Diazo shenanigans. Is the site control panel the right place for the |
Btw. when enabling, the ajax main template is not used very much. Currently I just saw it used for only for the rename dialog :D But! I experimented a bit with automatic XHR requests for any internal link within a site for some projects with quite promising results. This can achieved by something similar like: import pat_inject from "@patternslib/patternslib/src/pat/inject/inject";
import registry from "@patternslib/patternslib/src/core/registry";
// Add a new trigger for the inject pattern.
// NOTE: This uses pat-inject AJAX loading for all internal links with exceptions.
registry.patterns.inject.trigger = `${registry.patterns.inject.trigger}, .pat-inject a[href^="${window.location.origin}"]:not(.dropdown-toggle):not([id^="autotoc"])`; and in html: <body class="pat-inject"
data-pat-inject="
source: main::element;
target: main::element;
history: record &&
source: head title;
target: head title &&
source: #language_navigation::element;
target: #language_navigation::element &&
source: head link[rel=canonical]::element;
target: head link[rel=canonical]::element;
"
> |
ajax_disable_diazo sounds like something that should be part of IThemeSettings in https://github.com/plone/plone.app.theming/blob/master/src/plone/app/theming/interfaces.py#L89 |
Sorry for being late here. I like the final approach with But using them in CMFPlone's main_template view brings us back to the complexity of separating Classic-UI from core ... consequently And I'd also put the configuration options to the |
Classic-UI goes SPA in 3 lines of javascript ... I like! 😄 |
Related:
#4169
plone/plonetheme.barceloneta#404
Plone 6.1: #4188not addressing 6.1 anymore. Review comments addressed here.Plone 6.2: #4169 (this one)
Zope maintains the "HTTP_X_REQUESTED_WITH" request header. If this is set to "XMLHttpRequest", we have an AJAX request. If so, the ajax_load parameter is set to "true", regardless if it was set manually or not.
This should make use for the ajax_main_template for any AJAX request, potentially speeding up classic Plone by avoiding loading unnecessary stuff.
Update: Added @davisagli and @ale-rt for more opinions on that.