Problem/Motivation
Sites upgrading from earlier versions to this jquery_update 7.x-4.x version can have the jquery_update_jquery_version variable set to currently unsupported value (like 1.10, or so). This will cause the non-existing URL of jquery.js inserted to the site header and potentially broken sites.
I think we need to either update the jquery_update_jquery_replace() to fallback to the default jquery version, if the version from the variable is not supported anymore:
$supported_versions = jquery_update_get_supported_versions();
if (!in_array($version, $supported_versions)) {
$version = JQUERY_UPDATE_DEFAULT_JQUERY_VERSION;
}
Or create an update hook to update the jquery_update_jquery_version variable (global variable + themes variable - see theme_get_setting('jquery_update_jquery_version')).
The first one is safer in case that the update hook is not run, so that the page will be still working, but creates some "confusion", because the jQuery version select will have a default value not present in the select, etc...
The second option should be a cleaner solution.
Steps to reproduce
Set one of the removed jquery versions in the jquery_update 7.x-2.7 (or 7.x-4.x-alpha) and upgrade to the latest 7.x-4.x-dev. The jquery.js inserted in the page header is non-existent / broken.
Proposed resolution
Create an update hook or fallback in the jquery_update_jquery_replace() function.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3312186-13.patch | 5.76 KB | mcdruid |
| #13 | interdiff-3312186-10-13.txt | 2.26 KB | mcdruid |
| #11 | interdiff_3312186-8_10.txt | 3.7 KB | poker10 |
| #10 | 3312186-10.patch | 5.51 KB | poker10 |
| #8 | 3312186-8.patch | 5.26 KB | mcdruid |
Comments
Comment #2
mcdruid commentedGood idea to have a fallback if the variable doesn't match available settings.
I wrote an update hook in the early patches in #3166985: [Proposal] provide supported / recommended jQuery versions for Security coverage which might help as a starting point.
Technically we could say this is a new branch and there's no smooth upgrade path, but I think a few simple measures to avoid the most obvious problems that sites will hit would be worthwhile.
Comment #3
poker10 commentedI have tested the update hook from the #3166985-2: [Proposal] provide supported / recommended jQuery versions for Security coverage and it seems to work. Attaching a patch with this update hook, fallback in the
jquery_update_jquery_replace()function and a test (testing the fallback).Please review this and consider if we need both (update hook + fallback) or not.
Comment #5
mcdruid commentedDo we need to make sure we've included the .module file here too (as that's where the constant is defined)?
If this might happen repeatedly on an upgraded site, would we be better to put the helper function in the .module file and include it when we need to from .install rather than the other way around?
In general, I wonder about silently remapping a variable that no longer matches the module's available options to either 1.12 or 2.2 on every request.
Perhaps that'd be okay if we also show a warning in the admin UI / Status report to show that's what's going on?
Or we could store the remapped value, but I'm not certain we should do that without human supervision.
Comment #6
mcdruid commentedOh also, any sites that have already moved to 7.x-4.x and are happily using - say - a custom jQuery 3.6.1...
We'd want to avoid remapping them to jQuery 2.4 obviously! I'm guessing that would not have happened because it'd have been in supported options?
However, I've actually just removed the
jquery_update_get_supported_versions()function as we're no longer thinking in terms of supported / unsupported versions.So back to NW I think (largely my fault for changing things around in the last few days).
Comment #7
poker10 commentedThe custom jQuery paths are not affected by this fallback, because they are handled out before this code is executed.
So it only affects these versions which can be set in the version select. Currently there are only 1.12 and 2.2. If someone has another value in the
jquery_update_jquery_versionvariable, it can cause problems.But if we aggree that the update hook is enough, then I think it will be OK. I just wanted to show both options. The fallback was meant mainly to handle situation where "something went wrong" and the site still have wrong value in the variable. As you wrote, if we do not need to provide smooth upgrade path, then maybe we can leave here only the update hook and sites will need to check, if the variable are updated correctly after this.
This is a good point. If we keep the fallback it would be good to take a look at this. Perhaps if we detect an outdated version, we can run a code similar to the one in the update hook, to do one-time conversion. This would alo have a watchdog entry, so I think that it will be sufficient.
Comment #8
mcdruid commentedThis is partly a reroll and partly a refactor based on changes made in the module.
I don't think it addresses every point we've discussed in the last few comments, but hopefully we can start doing so from here.
Comment #9
mcdruid commentedOops.. back to NR for tests (which pass locally including the new one).
Comment #10
poker10 commentedOk, how about this - I have moved the logic of the version remap from the update hook to the module. And now using the same function in the update hook and in the fallback (if the version is different from the supported versions). This will ensure that the fallback will run only once if there will be unsupported version set.
Both these are fixed by your reroll / refactor.
It is now logged to the watchdog, if the conversion takes place from the fallback.
Comment #11
poker10 commentedSorry, I forgot to upload an interdiff.
Comment #12
mcdruid commentedI was a bit puzzled by this at first; why do we need to call the mapping function again when it was called by the first function?
It's because the variable / theme setting will have been updated if they needed to be, but we don't know whether jquery_update_jquery_replace() has been called with the main jQuery version or a specific one for a theme.
Perhaps we can add a comment to explain to the next person who wonders what's going on :)
Overall I think this looks pretty good. Great to have the tests too, thanks!
I was considering a slightly different approach where we allow the outdated version to be remapped on every request, but we raise a warning in the admin UI / status report to suggest that it gets fixed properly (building on some of what we've worked on recently in #3312151: improve jQuery Update's latest version checks).
Either approach ought to work, and there's an argument to say just fixing it once (and logging the change) is better.
In terms of having a runtime fallback and an update hook that do the same thing... I think that's okay. The British phrase is "belt and braces".
I might make a couple of tweaks to comments, but I think I'm going to commit this shortly.
Comment #13
mcdruid commentedChanges are almost all the comments. I've also renamed one function.
I'll do a little bit of manual testing upgrading a site, but I think this is ready to commit if tests still pass.
Comment #14
mcdruid commentedI tested installing the currently supported / recommended 7.x-2.7 release and enabling the defaults on a vanilla D7 site.
I then swapped out the jquery_update module for 7.x-4.x with the latest changes from this issue applied.
Without running db updates, refreshing the front page worked fine.
The script tags in the page went from e.g.:
..to:
I got a log message:
Running the database updates after this went without error.
The variable has been updated:
So I'd call that a success.
I'm sure there are plenty of other scenarios we could test for, but I think this covers the basic upgrade from the currently recommended release.
Thanks @poker10!
Comment #16
mcdruid commented