-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
✨Dev Dashboard: SSR'd Preact Components Using the Rollup JS API #18796
Conversation
super(); | ||
this.setState({ | ||
proxyInput: '', | ||
}); |
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 need to setState from the constructor, can create the state object with the default values.
}); | |
constructor() { | |
super(); | |
this.state = { proxyInput: '' }; | |
} |
this.setState({ | ||
...this.state, | ||
proxyInput: event.target.value, | ||
}); |
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.
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;
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.
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)} |
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.
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> | ||
{/* |
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.
This comment is obsolete now :)
}); | ||
} | ||
|
||
handleSubmit(event) { |
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.
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, '')}`;
}
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.
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", |
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.
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!
@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 😄 |
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.
@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.
@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 😄 |
@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}> |
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.
Super-nit: Rename handleSubmit
to submit
.
build-system/app.js
Outdated
@@ -62,11 +62,19 @@ app.get('/serve_mode=:mode', (req, res) => { | |||
}); | |||
|
|||
if (!global.AMP_TESTING) { | |||
app.get('/', serveIndex); | |||
|
|||
if ( |
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.
nit: use common-style:
if (process.env.DISABLE_DEV_DASHBOARD_CACHE &&
process.env.DISABLE_DEV_DASHBOARD_CACHE !== 'false') {
// ...
…v-dashboard-rollup-js-api
Made your requested changes 😄 |
@erwinmombay Said to just modify the |
…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
@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? amphtml/build-system/tasks/karma.conf.js Lines 75 to 97 in b843500
|
@rsimha Ah, so the output from that is actually the tests that were introduced by @alanorozco in #20651 😄 |
@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. |
This was done in #21125 |
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