Page MenuHomePhabricator

Explorer functionality broken on query.wikidata.org
Closed, ResolvedPublic

Description

Looks like something has been broken in Explorer functionality recently - when I click on the looking glass, I get the exception:

Uncaught TypeError: l(...).dialog is not a function
    at e.handleExploreItem (wdqs.min.156ce14a81d56066d505.js:1)

This is in Chrome on OS X.

Event Timeline

Looks like two first exceptions are red herring, only the last one is the real one. This is the code:

		currentDialog = $.parseHTML( currentDialog )[1];
		var dialog = $( currentDialog ).dialog( {

Looks like currentDialog returned from parseHTML is one-element array. So [1] does not work. If I change it to [0] I get this:

"TypeError: Cannot read property 'width' of undefined
    at jQuery.fn.init.gj.widget.getHTMLConfig (http://localhost:8088/gui/node_modules/gijgo/js/gijgo.min.js:1:2473)
    at jQuery.fn.init.getHTMLConfig (http://localhost:8088/gui/node_modules/gijgo/js/gijgo.min.js:1:11031)
    at jQuery.fn.init.gj.widget.init (http://localhost:8088/gui/node_modules/gijgo/js/gijgo.min.js:1:1464)
    at jQuery.fn.init.init (http://localhost:8088/gui/node_modules/gijgo/js/gijgo.min.js:1:10720)
    at new gj.dialog.widget (http://localhost:8088/gui/node_modules/gijgo/js/gijgo.min.js:1:16685)
    at jQuery.fn.init.a.fn.dialog (http://localhost:8088/gui/node_modules/gijgo/js/gijgo.min.js:1:17097)
    at SELF.wikibase.queryService.ui.resultBrowser.helper.FormatterHelper.SELF.handleExploreItem (http://localhost:8088/gui/wikibase/queryService/ui/resultBrowser/helper/FormatterHelper.js:391:35)
    at HTMLAnchorElement.proxy (http://localhost:8088/gui/node_modules/jquery/dist/jquery.js:10268:13)
    at HTMLAnchorElement.<anonymous> (http://localhost:8088/gui/node_modules/bootstrap-table/dist/bootstrap-table.js:2053:30)
    at HTMLAnchorElement.dispatch (http://localhost:8088/gui/node_modules/jquery/dist/jquery.js:5183:27)
    at HTMLAnchorElement.elemData.handle (http://localhost:8088/gui/node_modules/jquery/dist/jquery.js:4991:28)"

Change 440486 had a related patch set uploaded (by Smalyshev; owner: Smalyshev):
[wikidata/query/gui@master] Fix ws-sensitivity in Explorer

https://gerrit.wikimedia.org/r/440486

OK, I figured out what's going on. $( '#explorer-dialogs' ).html() returns HTML with whitespace. jQuery docs say:

jQuery.parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These methods do render all trailing or leading text (even if that's just whitespace). To prevent trailing/leading whitespace from being converted to text nodes you can pass the HTML string through jQuery.trim.

This is why the code worked with [1]. However, before deployment, the code is minimized, which stripped extra whitespace, thus making the real node [0], not [1]. This is why it worked in deployment (with WS) but not in production (stripped WS).

Proper solution is, just like jQuery docs say, to apply trim().

@Smalyshev, the above fix works, but using jQuery's clone() method in the original code will be a better approach. I'd like to make the changes recommended here.
That will remove the need for the above fix and will also fix the parent issue.

@prssanna Please feel free to submit the patch! My patch is just a stopgap measure to fix the breakage, if you have better ideas definitely let's improve it.

Change 440512 had a related patch set uploaded (by Prssanna; owner: Prssanna):
[wikidata/query/gui@master] Refactor handleExploreItem() and fix broken explorer functionality as well as positioning of the toolbar and edit query button on the explorer dialog.

https://gerrit.wikimedia.org/r/440512

Change 440512 merged by jenkins-bot:
[wikidata/query/gui@master] Refactor handleExploreItem() and fix broken explorer functionality

https://gerrit.wikimedia.org/r/440512

Change 440523 had a related patch set uploaded (by WDQSGuiBuilder; owner: WDQSGuiBuilder):
[wikidata/query/gui-deploy@production] Merging from ddae966c88faf5f8d1342fcbd84bd3bc0e6ed87c:

https://gerrit.wikimedia.org/r/440523

Change 440523 merged by Smalyshev:
[wikidata/query/gui-deploy@production] Merging from ddae966c88faf5f8d1342fcbd84bd3bc0e6ed87c:

https://gerrit.wikimedia.org/r/440523

Change 440486 abandoned by Smalyshev:
Fix ws-sensitivity in Explorer

Reason:
better fix checked in

https://gerrit.wikimedia.org/r/440486

Smalyshev claimed this task.
Vvjjkkii renamed this task from Explorer functionality broken on query.wikidata.org to hzaaaaaaaa.Jul 1 2018, 1:03 AM
Vvjjkkii reopened this task as Open.
Vvjjkkii removed Smalyshev as the assignee of this task.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed subscribers: gerritbot, Aklapper.