-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding an app for redirects when storing state in session storage #10822
Conversation
jenkins test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great, while I still don't love the solution we don't have many options 🤷♂️
}; | ||
|
||
import uiRoutes from 'ui/routes'; | ||
uiRoutes.enable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the router here? Enabling the router runs all of the route setup work, which just slows down this simple page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I'll remove it.
import { parse as parseUrl, format as formatUrl } from 'url'; | ||
import { stringify as stringifyQuerystring } from 'querystring'; | ||
|
||
const conservativeStringifyQuerystring = (query) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this hashing logic should be put in the state_management
module next to src/ui/public/state_management/state_hashing/unhash_url.js, and it definitely needs tests.
const uiSettings = server.uiSettings(); | ||
const stateStoreInSessionStorage = await uiSettings.get(request, 'state:storeInSessionStorage'); | ||
if (!stateStoreInSessionStorage) { | ||
reply().redirect(config.get('server.basePath') + url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to return
here
src/server/http/index.js
Outdated
} catch (err) { | ||
console.log(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks!
src/ui/index.js
Outdated
@@ -83,12 +83,12 @@ export default async (kbnServer, server, config) => { | |||
vars: await reduceAsync( | |||
uiExports.injectedVarsReplacers, | |||
async (acc, replacer) => await replacer(acc, request, server), | |||
defaults(await app.getInjectedVars() || {}, uiExports.defaultInjectedVars) | |||
defaults(await app.getInjectedVars() || {}, uiExports.defaultInjectedVars, vars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rename vars
-> injectedVarsOverrides
and move it to the front of the list here. If the code calling renderApp()
has specific vars in mind they shouldn't be overridden by the defaults or the standard injected vars, only the "replacers" could override them.
a45365b
to
e3051c3
Compare
@spalger I've addressed your concerns/comments, except the comment about not using the routing. I tried to do the following to remove the need for routing 14b09e3 but this led to the code being run whenever the javascript was loaded, is there a different way that I should be removing the need to use routing? |
I'm not sure I understand the issue. |
If the following is run every-time that load Kibana in a browser:
it'll always try to redirect the user, when we only want it to be ran after the following call:
|
fixes #10128 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, aside from a couple minor things.
}); | ||
}; | ||
|
||
export default hashUrl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more default exports, pleeease :) I will add an eslint rule to the ui/public folder this week, working on the last chunk of conversions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you got it! old habits die hard...
@@ -0,0 +1,4 @@ | |||
{ | |||
"name": "state_session_storage_redirect", | |||
"version": "kibana" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either here in a description block, or in index.js, can you add a comment describing the need for this and link to the github issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I'll add a description in here.
e3051c3
to
3f559e3
Compare
…astic#10822) * Adding an app for redirects when storing state in session storage * Removing errant console.log * Adding early return after reply().redirect * No longer using the router * Renaming vars to injectedVarsOverrides * Putting uiRoutes back in so the code is only executed for this app * Extracting hash_url to it's own module, and adding tests * Addressing peer-review comments
…0822) (#11305) * Adding an app for redirects when storing state in session storage * Removing errant console.log * Adding early return after reply().redirect * No longer using the router * Renaming vars to injectedVarsOverrides * Putting uiRoutes back in so the code is only executed for this app * Extracting hash_url to it's own module, and adding tests * Addressing peer-review comments
Backported 5.x - 9ca5059 |
When using the
state:storeInSessionStorage
setting with the short-urls, we were previously doing areply().redirect(fullUrl)
and then the state was being extracted from the URL and being put into sessionStorage. This was causing issues with IE where the URL was too long.This approach uses a separate 'app' and a variable that it's grabbing from the kbn-initial-state to get all the information to the browser, where it then puts it in sessionStorage before redirecting the user to the URL with the shortened hashes. It's not an incredibly elegant solution, and the user experience is somewhat 'choppy' for lack of a better description.
I'm open to alternatives to the current approach, but what's in this PR should work.
Resolves #10128