Skip to content

Commit

Permalink
fix/more typeahead fails (#3065)
Browse files Browse the repository at this point in the history
* Ensure typeahead jQuery extensions are loaded

We have at least the following jQuery versions in use:

1. `2.2.4` supplied from NPM, esbuild includes it in the chunks we later
   load.
2. `2.2.4` supplied from a script-tag in (dashboard)-base (with fallback to
   now defunct self-hosted static file).
    - This is the "global" jQuery most of the time.
3. `3.1.1` in use in templates/dashboard/events/details.html
4. `3.2.1` for django-wiki in templates/wiki/base.html

On most of dashboard the global 2.2.4 is in use, not the one from NPM.

It appears that the typeahead library has its own way of finding out
_which_ global jQuery version it should apply to. Since esbuild is set
to output in [ESM-format](https://esbuild.github.io/api/#format-esm),
it does some transformation of CommonJs-code (module.exports), which
means that `require/module` is defined in the _browser_ (where we are running).

Is there a better way to fix this? Yes, remove the code and be in sync
around one version, or isolate them better. Is it worth using any more
time on this? No.

The two 2.2.4 are _different objects_ so you can end in a
situation where `jQuery === $` is `false`. That is what happens when these
imports are uncommented, since only the name imported is the one changed
to the NPM-supplied version.

See: 6735dda,
812c7bb, 53b57b9

* Remove scrollspy-ing

There is a scrollspy function in initFrontpage.js, it appears to not be
related? User-search is likely to get removed anyways.
  • Loading branch information
henrikhorluck authored Nov 18, 2023
1 parent b9aaab1 commit 4b3e013
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion assets/dashboard/groups/group.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import jQuery from 'jquery';
import jQuery from 'jquery';
import { plainUserTypeahead } from 'common/typeahead';
import { ajax, showStatusMessage } from 'common/utils';

Expand Down
2 changes: 1 addition & 1 deletion assets/dashboard/marks/marks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import jQuery from 'jquery';
import jQuery from 'jquery';
import { plainUserTypeahead } from 'common/typeahead';
import { ajax, showStatusMessage } from 'common/utils';

Expand Down
2 changes: 1 addition & 1 deletion assets/dashboard/photoalbum/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Urls from 'common/utils/django_reverse';
// import $ from 'jquery';
import $ from 'jquery';
import { plainUserTypeahead } from 'common/typeahead';
import Cookies from 'js-cookie';

Expand Down
6 changes: 1 addition & 5 deletions assets/profiles/userSearch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import $ from 'jquery';
import $ from 'jquery';
import { userTypeahead } from 'common/typeahead';
import Spinner from 'spin.js';
import './less/typeahead.less';
Expand Down Expand Up @@ -26,9 +26,5 @@ export default () => {
$(window).load(() => {
$('.affix-spinner-wrapper').remove();
$('.affix').show();
$('body').scrollspy({
target: '#affix',
offset: 90,
});
});
};

0 comments on commit 4b3e013

Please sign in to comment.