Skip to content

bootstrap ui in script file rather than inline#15904

Merged
epixa merged 5 commits intoelastic:masterfrom
epixa:remove-inline-scripts
Feb 5, 2018
Merged

bootstrap ui in script file rather than inline#15904
epixa merged 5 commits intoelastic:masterfrom
epixa:remove-inline-scripts

Conversation

@epixa
Copy link
Contributor

@epixa epixa commented Jan 8, 2018

There's no good reason to bootstrap the UI within the browser using an
inline script tag rather than a separate dynamically created bootstrap
script.

Having this bootstrapping logic in its own file allows us to cache this
separately from the main HTML payload, and it is required if we want to
disable inline scripts entirely.

The UI bootstrapping logic is now served up on an app-specific .js
endpoint. The URL for the boostrap must contain the app id so that it
can load the relevant app-specific JS bundles on the fly.

The HTTP caching will be invalidated whenever the underlying template
changes, the interpolated data changes, or any translations change.

This is necessary for #2873

@epixa epixa added Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// release_note:enhancement labels Jan 8, 2018
@epixa epixa force-pushed the remove-inline-scripts branch from 38239fc to 2ec48a3 Compare January 8, 2018 20:06
Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some notes, excited about the direction here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why not just hash the result of #getJsFile()? Feels like that is what this method is claiming to do, but is avoiding it for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I arrived at this current implementation after some refactoring, and it's not ideal.

Copy link
Contributor

@spalger spalger Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we put everything within the try {} catch {}, and threw the error on 41 rather than passing it directly to reply(), then this handler would have a single flow for errors and would properly route errors if server.getUiAppById() threw, or request.params wasn't defined for some reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

Copy link
Contributor

@spalger spalger Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably just replace the next line

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the translation for the key foo in the js file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key is foo in the mock template for this test. In the actual template, it is UI-WELCOME_ERROR, which is the translation key for the error message that is shown when bundles fail to load properly: https://github.com/elastic/kibana/blob/master/src/ui/ui_render/views/ui_app.jade#L143

@epixa
Copy link
Contributor Author

epixa commented Jan 8, 2018

@spalger I pushed changes for your feedback

@epixa
Copy link
Contributor Author

epixa commented Jan 9, 2018

This is breaking for the status page. I'll check it out tomorrow.

@epixa epixa removed the blocked label Jan 9, 2018
@epixa
Copy link
Contributor Author

epixa commented Jan 9, 2018

#15880 was merged, so this PR is unblocked

epixa added 2 commits February 4, 2018 15:17
There's no good reason to bootstrap the UI within the browser using an
inline script tag rather than a separate dynamically created bootstrap
script.

Having this bootstrapping logic in its own file allows us to cache this
separately from the main HTML payload, and it is required if we want to
disable inline scripts entirely.
@epixa epixa force-pushed the remove-inline-scripts branch from cb020d8 to d271851 Compare February 4, 2018 20:19
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@epixa
Copy link
Contributor Author

epixa commented Feb 4, 2018

@spalger Sorted out the status page issue and ready for another look.

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing I think


server.route({
path: '/bundles/app/{id}/bootstrap.js',
method: 'GET',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure this gets config: { auth: false }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. I pushed this up and merged with the latest master.

epixa added 2 commits February 5, 2018 14:34
We do not require auth for the rest of our static JS files, and this
file should not be treated differently than those. That this file is
created dynamically rather than pulled directly from the file system
is just an implementation detail.
@elasticmachine
Copy link
Contributor

💔 Build Failed

@epixa
Copy link
Contributor Author

epixa commented Feb 5, 2018

jenkins, test this

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@epixa
Copy link
Contributor Author

epixa commented Feb 5, 2018

I pinged the visualizations team about that random test failure. It was some threshold-based test failing in a flaky way, so they're looking into it.

@epixa epixa merged commit 2896a13 into elastic:master Feb 5, 2018
@epixa epixa deleted the remove-inline-scripts branch February 5, 2018 21:22
epixa added a commit to epixa/kibana that referenced this pull request Feb 5, 2018
* bootstrap ui in script file rather than inline

There's no good reason to bootstrap the UI within the browser using an
inline script tag rather than a separate dynamically created bootstrap
script.

Having this bootstrapping logic in its own file allows us to cache this
separately from the main HTML payload, and it is required if we want to
disable inline scripts entirely.

* cleanup from review 1

* fix status page bootstrap

* do not require auth for app bootstrap files

We do not require auth for the rest of our static JS files, and this
file should not be treated differently than those. That this file is
created dynamically rather than pulled directly from the file system
is just an implementation detail.
epixa added a commit that referenced this pull request Feb 5, 2018
* bootstrap ui in script file rather than inline

There's no good reason to bootstrap the UI within the browser using an
inline script tag rather than a separate dynamically created bootstrap
script.

Having this bootstrapping logic in its own file allows us to cache this
separately from the main HTML payload, and it is required if we want to
disable inline scripts entirely.

* cleanup from review 1

* fix status page bootstrap

* do not require auth for app bootstrap files

We do not require auth for the rest of our static JS files, and this
file should not be treated differently than those. That this file is
created dynamically rather than pulled directly from the file system
is just an implementation detail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v6.3.0 v7.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants