Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
"handlebars": "^4.0.10",
"hapi-auth-cookie": "^9.0.0",
"history": "4.7.2",
"history-extra": "^4.0.2",
"humps": "2.0.1",
"icalendar": "0.7.1",
"inline-style": "^2.0.0",
Expand Down Expand Up @@ -268,4 +269,4 @@
"engines": {
"yarn": "^1.6.0"
}
}
}
23 changes: 3 additions & 20 deletions x-pack/plugins/canvas/public/lib/history_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import chrome from 'ui/chrome';
import lzString from 'lz-string';
import { createBrowserHistory, createMemoryHistory, parsePath, createPath } from 'history';
import { get } from 'lodash';
import { APP_ROUTE } from '../../common/lib/constants';
import { createMemoryHistory, parsePath, createPath } from 'history';
import createHashStateHistory from 'history-extra';
import { getWindow } from './get_window';

function wrapHistoryInstance(history) {
Expand Down Expand Up @@ -132,29 +130,14 @@ const instances = new WeakMap();
const getHistoryInstance = win => {
// if no window object, use memory module
if (typeof win === 'undefined' || !win.history) return createMemoryHistory();

const basePath = chrome.getBasePath();
const basename = `${basePath}${APP_ROUTE}#/`;

// hacky fix for initial page load so basename matches with the hash
if (win.location.hash === '') win.history.replaceState({}, '', `${basename}`);

// if window object, create browser instance
return createBrowserHistory({
basename,
});
return createHashStateHistory();
};

export const historyProvider = (win = getWindow()) => {
// return cached instance if one exists
const instance = instances.get(win);
if (instance) return instance;

// temporary fix for search params before the hash; remove them via location redirect
// they can't be preserved given this upstream issue https://github.com/ReactTraining/history/issues/564
if (get(win, 'location.search', '').length > 0)
win.location = `${chrome.getBasePath()}${APP_ROUTE}${win.location.hash}`;

// create and cache wrapped history instance
const historyInstance = getHistoryInstance(win);
const wrappedInstance = wrapHistoryInstance(historyInstance);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10595,6 +10595,11 @@ highlight.js@^9.12.0, highlight.js@~9.12.0:
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.12.0.tgz#e6d9dbe57cbefe60751f02af336195870c90c01e"
integrity sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4=

history-extra@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/history-extra/-/history-extra-4.0.2.tgz#67b512c196e0a521be1d8ac83513f00ca761d9f3"
integrity sha512-Nia8vzQHyQcxKQUt5/vxZegurkG2K23TplaWLk1V6EWTuNdZMJUJ78anwGkBcHuLBia8TFUct/R/QDlgRUA42A==

history@4.7.2, history@^4.7.2:
version "4.7.2"
resolved "https://registry.yarnpkg.com/history/-/history-4.7.2.tgz#22b5c7f31633c5b8021c7f4a8a954ac139ee8d5b"
Expand Down