-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Lazy load babel on REPL #1318
Lazy load babel on REPL #1318
Conversation
js/repl/src/ReplOptions.js
Outdated
overflow: 'auto', | ||
boxSshadow: | ||
flexDirection: 'column', | ||
boxShadow: |
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.
@bvaughn found a typo we all missed :)
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.
🤡 It's not widely know, but the box-sshadow
is awesome
e262b33
to
cf7fe40
Compare
Deploy preview failed. Built with commit ece0494 https://app.netlify.com/sites/babel/deploys/599b45217960b1269842291f |
js/repl/src/Repl.js
Outdated
@@ -160,6 +162,27 @@ export default class Repl extends React.Component { | |||
); | |||
} | |||
|
|||
_setupBabel() { | |||
loadBabel(this.state.babel, success => { |
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.
We could refactor this alongside loadPlugins
to be a bit more generic, but figured we could do that in a follow up, if anything.
Couple of quick thoughts:
|
I think it's fine for the invalid build number since you would be going to the link via babel-bot not manually (you shouldn't be at least), make the 99% case fast (also circle ci isn't doing so hot atm https://status.circleci.com/) |
Would be nice to link to the corresponding PR, or github release |
Maybe we should hide this label unless the URL flag is specified? This way we don't eat up so much space. |
@bvaughn yeah, I'm still experimenting with other options. I think it's valuable to show the current Babel version at somewhere, though I agree it's currently taking up a bit more space than we'd like. |
I was kind of picturing an info/question icon that's either FAB-style or maybe shown only on hover. |
js/repl/src/loadBabel.js
Outdated
|
||
// No specific version passed, so just download the latest release. | ||
if (!version) { | ||
version = 'next'; // This should be changed to "latest" when Babel 7 is stable |
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.
Maybe this should actually be 6
since this is the stable REPL.
js/repl/src/loadBuildArtifacts.js
Outdated
} | ||
|
||
const artifacts = response.filter(x => | ||
/babel-standalone\/babel.js$/.test(x.path) |
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 have way more newlines than I did in my version... were my lines too long? 😛
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 ran prettier :)
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.
Prettier ftw 😁
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.
Prettier is SO NICE. I love it. We ran it across millions of lines of code at work.
js/repl/src/loadBuildArtifacts.js
Outdated
xhr.onload = function() { | ||
const response = JSON.parse(xhr.responseText); | ||
if (response.message) { | ||
alert(`Could not load Babel build #${build}: ${response.message}`); |
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 wanted to display these in a nicer way, but there was no good way to get the error message into the UI. Maybe we could improve that now with the new REPL?
The "repo" (Daniel15/babel in your example) is going to be very very rarely used, so I wouldn't bother showing it in the UI. Essentially, it will only differ if the PR is going to a different repo (just for testing purposes). For example, to test out CircleCI builds, I sent a PR from For CircleCI builds, we append the PR number to the version number: https://github.com/babel/babel/blob/7.0/packages/babel-standalone/src/gulpTasks.js#L19-L20. It'll look like |
cf7fe40
to
5b0b58f
Compare
I like the loading UI! 😄 I'm still not a fan of showing the version by default though. (I think it takes up too much space and adds too little value.) I think we should only show the version label if the user has specified a target version in the URL. That is, unless we can make it more subtle. |
I like a showing the version. It makes it obvious which version is being
used (for example, if there's an issue with babel-standalone and it doesn't
publish correctly, we'll see that there's an older version in use).
Sent from my phone.
…On Aug 18, 2017 9:14 AM, "Brian Vaughn" ***@***.***> wrote:
I like the loading UI! 😄
I'm still not a fan of showing the version by default though. I think we
should only show the version label if the user has specified a target
version in the URL.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1318 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFnHU-oiSg6g_3THkg8inU9TSJmbtJLks5sZbhagaJpZM4O30cb>
.
|
Do we really need the REPL UI to detect this case? 🤔 Sidebar space is precious, especially as we expand to add more options there (eg 3rd party plugins from NPM). I can see us needing to switch to an accordion UI in the near future to make more room for things. |
Knowing the version of babel-core is important if we want to use the repl as a way to report issues (ideally we'd have every version in some menu then I guess) |
One thing we could do is have the debug option always available (and not just for env's debug output), and output the version info there? |
Sounds like I'm in the minority here then 😄 in which case, that's cool. I'll defer. However, I still think we should at least change the visual treatment of it to be a part of the rest of the sidebar rather than being a sticky footer part. Making it sticky forces it to take up more space (since you can't even scroll it off screen if your screen is smaller.) |
I was going to take a quick stab at tweaking the version label but on this branch, Wondering if anyone else has seen this? |
@bvaughn jekyll hates you :) I have a fix for making the label part of the sidebar, will push in a sec |
Yeah maybe so...but I think it's worth confirming with at least one other person before merging.
Great 👍 |
Travis and Netlify are both OK with this diff... But they're robots so maybe they don't count as "other people" 😛 Also they're building the site ( |
Pfft 😆 Robots! Yes, $ make serve
bundle check || bundle install; \
bundle exec jekyll serve
The Gemfile's dependencies are satisfied
Configuration file: /Users/bvaughn/Documents/git/babel.github.io/_config.yml
Configuration file: /Users/bvaughn/Documents/git/babel.github.io/_config.yml
Source: /Users/bvaughn/Documents/git/babel.github.io
Destination: /Users/bvaughn/Documents/git/babel.github.io/_site
Incremental build: disabled. Enable with --incremental
Generating... Compare to $ make serve
# Run both Jekyll and Webpack concurrently.
make -j2 serve-jekyll serve-webpack
./node_modules/.bin/webpack-dev-server
bundle check || bundle install; \
bundle exec jekyll serve --incremental
The Gemfile's dependencies are satisfied
Project is running at http://localhost:34512/
webpack output is served from http://localhost:34512/
Configuration file: /Users/bvaughn/Documents/git/babel.github.io/_config.yml
Source: /Users/bvaughn/Documents/git/babel.github.io
Destination: /Users/bvaughn/Documents/git/babel.github.io/_site
Incremental build: enabled
Generating...
Hash: d13355e738e68f810938
Version: webpack 3.5.4
Time: 2144ms Looks like this branch isn't kicking off |
Hmm that's very weird. I could try it on my computer but it won't be until tonight - All my Babel stuff is on my home PC rather than my work PC. |
d861c70
to
e95414e
Compare
Fetched and pulled and |
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.
Looks nice! Left a few minor things.
js/repl/PresetLoadingAnimation.js
Outdated
className: ?string, | ||
}; | ||
|
||
const PresetLoadingAnimation = ({ className }: PresetLoadingAnimationProps) => |
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.
subjective nit: Named param inline defaults are nice too for element props 😄
const PresetLoadingAnimation = ({ className = "" }: PresetLoadingAnimationProps) =>
js/repl/Repl.js
Outdated
} else { | ||
babelState.didError = true; | ||
babelState.isLoading = false; | ||
} |
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.
Mutable data in state
is kind of a sketchy part of my original design here, but I didn't want the added weight of pulling in a lib like Immutable. That being said-
Since you're just mutating state.babel
in this callback, and you pass state.babel
to loadBabel
- why not just have it wrap the callback and update the isLoaded
and isLoading
values before calling it? (That would be more consistent with what loadPlugin
does.)
minWidth: "150px", | ||
display: "flex", | ||
overflow: "auto", | ||
boxSshadow: | ||
boxShadow: |
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.
🤡
js/repl/ReplOptions.js
Outdated
paddingRight: "1.5rem", | ||
|
||
[media.large]: { | ||
borderTop: "2px solid #121417", |
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.
js/repl/UriUtils.js
Outdated
"evaluate", | ||
"lineWrap", | ||
"presets", | ||
"prettier", | ||
"showSidebar", | ||
"targets", | ||
"targets", |
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.
Duplicate "targets" ^
|
||
// See if a CircleCI build number was passed in the path | ||
// Prod (with URL rewriting): /repl/build/12345/ | ||
// Dev: /repl/#?build=12345 |
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.
Great 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.
Heh, this is my comment (this is copied across from 7.html
). I try to keep them informative. 😛
js/repl/loadBuildArtifacts.js
Outdated
if (!artifacts || artifacts.length === 0) { | ||
alert( | ||
`Could not find valid babel-standalone artifact in build #${build}` | ||
); |
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.
Why alert
? Shouldn't we invoke the callback with a false-success so our error state is consistent?
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.
Was originally trying to get the first version of this as a straight port of @Daniel15's original PR, but I'll go ahead bubble up the error through the callbacks and show it in the "Loading Babel" message.
js/repl/loadBuildArtifacts.js
Outdated
}; | ||
|
||
xhr.onerror = function() { | ||
alert(`Could not load Babel build #${build} :(`); |
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.
Ditto as above.
js/repl/loadBuildArtifacts.js
Outdated
@@ -0,0 +1,39 @@ | |||
export default function loadBuildArtifacts( | |||
repo: string = "babel/babel", |
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.
null
or empty string ""
will override default params, so I don't think this will actually work. (If no circleciRepo
query parameter is specified, an empty string gets passed to this function- since that's the default replUtils
sets.)
e95414e
to
848320b
Compare
@bvaughn thanks for the review, made the changes and now error messages bubble up to the loading screen; can follow up this PR with improved versions (tweak copy, can detect 404s on builds, probably add an error icon instead of sad face emoji, etc). |
Love it 😁 Happy to help with this |
js/repl/PresetLoadingAnimation.js
Outdated
const PresetLoadingAnimation = ({ | ||
className = "", | ||
}: PresetLoadingAnimationProps) => | ||
<div className={`${className || ""} ${styles.loadingAnimation}`}> |
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: className || ""
is redundant with the initializer above
js/repl/Repl.js
Outdated
if (!state.babel.isLoaded) { | ||
let message = "Loading Babel..."; | ||
|
||
if (!state.babel.isLoading && state.babel.didError) { |
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: state.babel.didError
should be sufficient?
js/repl/Repl.js
Outdated
})); | ||
|
||
if (babelState.isLoaded) { | ||
this._checkForUnloadedPlugins(); |
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.
Should this be done in the setState
callback?
} | ||
} | ||
|
||
cb(url, error); |
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.
Would be good to use promises here, but then I guess we'd need to load a polyfill (maybe?)
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 looks good! shipit!
Fixes #1313.
EDIT:
Reduced it to a simple version string output: