From d0d926b8a977e79151d5970d3fc7995f5943e9fc Mon Sep 17 00:00:00 2001 From: Matthew Bargar Date: Mon, 17 Oct 2016 17:07:11 -0400 Subject: [PATCH] Stop Discover's Visualize button from loading incorrect URL When App state is read from the url, it is accessed via `$location.search()`. It turns out that the result of `$location.search()` is a mutable object that allows you to modify the results of `$location.search()` without actually modifying the URL. When a user clicks a field in the Discover sidebar, it executes the scope method `vizLocation` to get the href value for the "Visualize" button. As an unintended side effect, `vizLocation` was modifying the object returned from `$location.search()`. This change would ultimately be read when the Visualize app loaded instead of the param in the actual URL since there's no full page load from Discover -> Visualize. To make things more complicated, I believe there was a race condition partially masking this issue. Since `vizLocation` is used in an Angular string template, the data binding causes it to execute on every digest cycle. This is why the incorrect value continued to be written to `$location.search()` even after `visLocation` ran for the correct field. It also meant that the result of `$location.search()` was totally dependent on which field `vizLocation` ran for most recently before the user clicked Visualize. Fixes https://github.com/elastic/kibana/issues/8718 --- .../public/discover/components/field_chooser/field_chooser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js b/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js index abca05ed1fb32..1295301146037 100644 --- a/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js +++ b/src/core_plugins/kibana/public/discover/components/field_chooser/field_chooser.js @@ -194,7 +194,7 @@ app.directive('discFieldChooser', function ($location, globalState, config, $rou }; } - return '#/visualize/create?' + $.param(_.assign($location.search(), { + return '#/visualize/create?' + $.param(_.assign(_.clone($location.search()), { indexPattern: $scope.state.index, type: type, _a: rison.encode({