Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13509 closed defect (fixed)

jquery error around "unload" function

Reported by: clemens Owned by: clemens
Priority: normal Component: DataSaverPlugin
Severity: blocker Keywords:
Cc: Trac Release: 1.2

Description

The DataSaverPlugin (revision r15561) does not work with modern jquery versions.

It produces the following Javascript error $(...).unload is not a function.

Running Trac 1.2.2, with Windows Firefox 63.

It looks like the problem is usage of the deprecated unload function in the datasaver JS routine:

    $(window).unload(datasaver_savior) // DEPRECATED

The following the a proper replacement

    $(window).on("unload",datasaver_savior)

This is what I learned from Denys Séguret at stackoverflow:

This function was first deprecated in 1.8 and then removed. You could in theory replace it with .on("unload", function(){ which it was a shortcut for.
But it was removed for a good reason: listening for this event is usually a bad practice. The truth is there's no real cross-browser and reliable solution to handle page termination. The real solution is to avoid relying on this event. You must design your application so that you don't have anything to do on page closing.

Attachments (0)

Change History (8)

comment:1 Changed 5 years ago by Ryan J Ollos

In 17317:

TracDataSaver 3.0dev: Require Trac >= 1.0

Changed plugin name in preparation for publishing to PyPI.
Remove old plugin using pip before installing new plugin:

$ pip uninstall DataSaverPlugin

Refs #13509

comment:2 in reply to:  description ; Changed 5 years ago by Ryan J Ollos

Replying to clemens:

The DataSaverPlugin (revision r15561) does not work with modern jquery versions.

It does work with the versions of jQuery distributed with Trac (see JavaScript). Using a newer version is not recommended.

comment:3 Changed 5 years ago by Ryan J Ollos

Owner: set to Ryan J Ollos
Resolution: fixed
Status: newclosed

In 17318:

TracDataSaver 3.0dev: Replace deprecated unload

The method is deprecated in jQuery 1.8 and removed in
jQuery 3.0.

Patch by clemens.

Fixes #13509.

comment:4 Changed 5 years ago by Ryan J Ollos

Owner: changed from Ryan J Ollos to clemens

comment:5 in reply to:  2 ; Changed 5 years ago by clemens

Replying to Ryan J Ollos:

It does work with the versions of jQuery distributed with Trac (see JavaScript). Using a newer version is not recommended.

According to JavaScript Trac 1.2.x should come with 1.11.3. But it seems my TRAC (version 1.2.2, Debian 9 "stretch" linux server) is running with jQuery 3.2.1. Firefox debug console says:

jQuery.fn.jquery
"3.2.1"

I have no idea why I have this jQuery version. We did not mess around with that...
I invested deeper, but was not able to find out why. First I disabled all plugins - for testing. But my chrome/common/js/jquery.js is version 3.2.1.

We installed Trac as Debian package (i.e. not from source) and my guess is that Debian package makers bundled another jQuery version. On my debian server I found a soft-link in /usr/lib/python2.7/dist-packages/trac/htdocs/js/jquery.js which point to a file /usr/share/javascript/jquery/jquery.min.js. This JS file jQuery version 3.2.1. I expect this is the case why my Trac is served with that jQuery version.

Bottom line is: Ryan, you are right, I am running the "wrong" (too new) jQuery version with TRAC. But I have no idea what is the background. Since you fixed the issue #13509, I have no problem with my jQuery version. If you believe I should dig into this, then I might ask also on the mailing list. Maybe we have some Debian TRAC experts there. Otherwise I would keep it as it is.

comment:6 in reply to:  3 ; Changed 5 years ago by clemens

Replying to Ryan J Ollos:

Fixes #13509.

Wow, Ryan. You are fast!
I never expect you are doing overnight service. Many, many thanks for your diligent commitment to TRAC.

Clemens

comment:7 in reply to:  5 Changed 5 years ago by Ryan J Ollos

Replying to clemens:

We installed Trac as Debian package (i.e. not from source) and my guess is that Debian package makers bundled another jQuery version.

Yeah, I've seen other reports on that as well. I'm surprised it doesn't cause more problems. If it ever becomes an issue, the easiest thing fix would be to use jQuery and jQuery-UI from a CDN (see TracIni#trac-jquery_location-option). But if it's working, I would not worry about it.

comment:8 in reply to:  6 Changed 5 years ago by Ryan J Ollos

Replying to clemens:

Wow, Ryan. You are fast!
I never expect you are doing overnight service. Many, many thanks for your diligent commitment to TRAC.

Easy to do since you provided the patch. Thanks!

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain clemens.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.