Skip to content
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

✨Dev Dashboard: SSR'd Preact Components Using the Rollup JS API #18796

Merged
merged 17 commits into from
Oct 19, 2018

Conversation

torch2424
Copy link
Contributor

Inspired by an offline discussion regarding #18719 .

This uses the Rollup JS API to create bundles for components as we serve them on their respective routes. This can be improved in the future, and do things like server side pre rendering for Preact.

This is currently made to "fit in" to the current architecture, though this can be improved as we move out more html snippets into respective JS components.

This increases our "/" by ~20KB, and initial bundling takes ~1.5s from my experience.

This also implements a flag for caching the routes that we generate bundles for 😄

Example

devdashboardrollup

super();
this.setState({
proxyInput: '',
});
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to setState from the constructor, can create the state object with the default values.

Suggested change
});
constructor() {
super();
this.state = { proxyInput: '' };
}

this.setState({
...this.state,
proxyInput: event.target.value,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The only item modified can be updated here.

this.setState({proxyInput:event.target.value});

If you're looking for previous state, its likely a good idea to use the other signature for setState.

setState<K extends keyof StateType>(state:Pick<StateType, K>, callback?:() => void):void;
setState<K extends keyof StateType>(fn:(prevState:StateType, props:PropsType) => Pick<StateType, K>, callback?:() => void):void;

Copy link
Member

@alanorozco alanorozco left a comment

Choose a reason for hiding this comment

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

Cool to leave as-is for now, but maybe I can take a stab at component-izing template.html.

required aria-required="true"
placeholder="https://"
value={this.state.proxyInput}
onChange={event => this.handleProxyInputChange(event)}
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't need to be state-synced, just getting input.value should be fine.

<form id="proxy-form" onSubmit={event => this.handleSubmit(event)}>
<label for="proxy-input">
<span>Load URL by Proxy</span>
{/*
Copy link
Member

Choose a reason for hiding this comment

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

This comment is obsolete now :)

});
}

handleSubmit(event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use the arrow syntax when defining this method and autobind this to avoid doing so in the render loop.

handleSubmit = event => {
  event.preventDefault();
  window.location = `/proxy/s/${this.state.proxyInput.replace(/^http(s?):\/\//i, '')}`;
}

Copy link
Member

@alanorozco alanorozco left a comment

Choose a reason for hiding this comment

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

Since this is being bundled on serve-time, is there any way we can pass arguments as part of the build?

This is interesting to pass component children and get rid of our comment-replacement-output scheme.

package.json Outdated
@@ -166,6 +167,10 @@
"request": "2.88.0",
"rimraf": "2.6.2",
"rocambole": "0.7.0",
"rollup": "^0.66.6",
Copy link
Contributor

Choose a reason for hiding this comment

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

Likely want to pin these dependencies and let renovate update them.

Which means you'll need some tests to ensure updates don't break anything!

@torch2424
Copy link
Contributor Author

@alanorozco Yes definitely! We should be able to just pass in components. Let's try and do this in another PR, once this gets in 😄

Also, need to write tests per @kristoferbaxter 's comment 😄

Copy link
Member

@alanorozco alanorozco left a comment

Choose a reason for hiding this comment

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

@torch2424 One more thing I forgot, this will not update the file listings unless the server is restarted. We need to be serving the listing state some other way.

@torch2424
Copy link
Contributor Author

@alanorozco Yes, after discussing with @kristoferbaxter , We can try and go down the JSON Rest API approach.

Let's handle that in another PR though 😄

@torch2424
Copy link
Contributor Author

@kristoferbaxter @erwinmombay @alanorozco

Added tests, and all the gulp stuff to get tests running with travis and everything.

This should be good to go for another round of reviews! 😄

render() {
return (
<div class="block proxy-form-container">
<form id="proxy-form" onSubmit={this.handleSubmit}>
Copy link
Member

Choose a reason for hiding this comment

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

Super-nit: Rename handleSubmit to submit.

@@ -62,11 +62,19 @@ app.get('/serve_mode=:mode', (req, res) => {
});

if (!global.AMP_TESTING) {
app.get('/', serveIndex);

if (
Copy link
Member

Choose a reason for hiding this comment

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

nit: use common-style:

if (process.env.DISABLE_DEV_DASHBOARD_CACHE &&
    process.env.DISABLE_DEV_DASHBOARD_CACHE !== 'false') {
  // ...

@torch2424
Copy link
Contributor Author

@alanorozco

Made your requested changes 😄

@torch2424
Copy link
Contributor Author

@erwinmombay Said to just modify the determineBuildTarget, that way we get the correct target set for files, and that way we can make dev dashboard tests run at the correct time 😄 Other than that, looks good and we can merge

@torch2424
Copy link
Contributor Author

Got dev dashboard tests running in travis 😄

screen shot 2018-10-18 at 5 51 59 pm

@torch2424 torch2424 merged commit 1146a59 into ampproject:master Oct 19, 2018
@torch2424 torch2424 deleted the dev-dashboard-rollup-js-api branch October 19, 2018 01:05
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
…roject#18796)

* Got a server side rendered bundle

* Finished the proxy form component

* Allowed disabling/enabling dev dashboard cache

* Fixed caching issues

* Added file header

* Fixed all build-system errors

* Made PR Changes

* Started tests

* Got dev dashboard tests running

* Added a nice dev dashboard message for unit tests

* Fixed lint errors and things

* Made PR Changes

* Added support for DEV_DASHBOARD Parallelization and targeting

* Fixed dev dashboard tests not running in travis

* Linr fix
@rsimha
Copy link
Contributor

rsimha commented Feb 19, 2019

@torch2424 Sorry to bump such an old PR. I just noticed that the dev dashboard test output is pretty verbose. See https://travis-ci.org/ampproject/amphtml/jobs/493956091#L1523-L1607

Any chance you can use the same dots reporters that are used by the unit and integration tests?

reporters: ['super-dots', 'karmaSimpleReporter'],
superDotsReporter: {
nbDotsPerLine: 100000,
color: {
success: 'green',
failure: 'red',
ignore: 'yellow',
},
icon: {
success: '●',
failure: '●',
ignore: '○',
},
},
specReporter: {
suppressPassed: true,
suppressSkipped: true,
suppressFailed: false,
suppressErrorSummary: true,
maxLogLines: 20,
},

@torch2424
Copy link
Contributor Author

@rsimha Ah, so the output from that is actually the tests that were introduced by @alanorozco in #20651

😄

@alanorozco
Copy link
Member

@torch2424 Totally, but I hadn't noticed that they output like that all the time. If any of you, @rsimha or @torch2424 can point me to how to plug-in this karma config to our devdash tests I can do that.

@rsimha
Copy link
Contributor

rsimha commented Feb 27, 2019

This was done in #21125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants