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

Lazy load babel on REPL #1318

Merged
merged 4 commits into from
Aug 22, 2017
Merged

Lazy load babel on REPL #1318

merged 4 commits into from
Aug 22, 2017

Conversation

existentialism
Copy link
Member

@existentialism existentialism commented Aug 15, 2017

Fixes #1313.

EDIT:

Reduced it to a simple version string output:

image

overflow: 'auto',
boxSshadow:
flexDirection: 'column',
boxShadow:
Copy link
Member Author

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 :)

Copy link
Contributor

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

@babel-bot
Copy link
Contributor

babel-bot commented Aug 15, 2017

Deploy preview failed.

Built with commit ece0494

https://app.netlify.com/sites/babel/deploys/599b45217960b1269842291f

@@ -160,6 +162,27 @@ export default class Repl extends React.Component {
);
}

_setupBabel() {
loadBabel(this.state.babel, success => {
Copy link
Member Author

@existentialism existentialism Aug 15, 2017

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.

@bvaughn
Copy link
Contributor

bvaughn commented Aug 15, 2017

Couple of quick thoughts:

  • Haven't reviewed the code yet, but the UI looks nice. 😄
  • The new label eats up a lot of space- especially for the responsive layout. I wonder if we can hide it by default somehow? (I'd be happy to help with this if you'd like!)
  • Passing an invalid build number causes things to hang for a long time waiting on a 500 response from circleci.com/api/v1.1/project/github//<invalidid>/artifacts and then we don't handle the error. (Maybe this is okay and it's not worth supporting?)

@hzoo
Copy link
Member

hzoo commented Aug 15, 2017

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/)

@hzoo
Copy link
Member

hzoo commented Aug 15, 2017

Would be nice to link to the corresponding PR, or github release

@bvaughn
Copy link
Contributor

bvaughn commented Aug 15, 2017

Maybe we should hide this label unless the URL flag is specified? This way we don't eat up so much space.

@existentialism
Copy link
Member Author

@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.

@bvaughn
Copy link
Contributor

bvaughn commented Aug 15, 2017

I was kind of picturing an info/question icon that's either FAB-style or maybe shown only on hover.


// 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
Copy link
Member

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.

}

const artifacts = response.filter(x =>
/babel-standalone\/babel.js$/.test(x.path)
Copy link
Member

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? 😛

Copy link
Member Author

Choose a reason for hiding this comment

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

I ran prettier :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Prettier ftw 😁

Copy link
Member

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.

xhr.onload = function() {
const response = JSON.parse(xhr.responseText);
if (response.message) {
alert(`Could not load Babel build #${build}: ${response.message}`);
Copy link
Member

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?

@Daniel15
Copy link
Member

Daniel15 commented Aug 16, 2017

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 Daniel15Test/babel to Daniel15/babel. For any PRs to the "real" Babel, it'll always be babel/babel as that's the CircleCI project that's being built.

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 6.24.0+pr.12345 or 7.0.0-alpha.15+pr.12345 where 12345 is the PR number. Given that, we probably don't need to show the build number in the UI. Although we could have multiple builds per PR (every time the user pushes to the branch, we'll build it again) so maybe it's beneficial to show the build number. Hmm.

@existentialism
Copy link
Member Author

existentialism commented Aug 18, 2017

@bvaughn @Daniel15 rebased/updated... basically reduced this to only output the version number.

We can probably unify the "Loading..." from the Jekyll template with the initial "Loading Babel..." state in a further PR.

@bvaughn
Copy link
Contributor

bvaughn commented Aug 18, 2017

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.

@Daniel15
Copy link
Member

Daniel15 commented Aug 18, 2017 via email

@bvaughn
Copy link
Contributor

bvaughn commented Aug 18, 2017

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

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.

@hzoo
Copy link
Member

hzoo commented Aug 18, 2017

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)

@existentialism
Copy link
Member Author

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?

@bvaughn
Copy link
Contributor

bvaughn commented Aug 18, 2017

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.)

@bvaughn
Copy link
Contributor

bvaughn commented Aug 18, 2017

I was going to take a quick stab at tweaking the version label but on this branch, make serve just hangs for me. Switching back to master works fine though.

Wondering if anyone else has seen this?

@existentialism
Copy link
Member Author

@bvaughn jekyll hates you :) I have a fix for making the label part of the sidebar, will push in a sec

@bvaughn
Copy link
Contributor

bvaughn commented Aug 18, 2017

jekyll hates you

Yeah maybe so...but I think it's worth confirming with at least one other person before merging.

I have a fix for making the label part of the sidebar, will push in a sec

Great 👍

@Daniel15
Copy link
Member

I think it's worth confirming with at least one other person before merging.

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 (make build) not watching. Could you try make build and see if that works for you?

@bvaughn
Copy link
Contributor

bvaughn commented Aug 18, 2017

Pfft 😆 Robots!

Yes, make build works for me. make serve hangs (although it's pretty speedy on master).

$ 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 master:

$ 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 webpack-dev-server?

@Daniel15
Copy link
Member

Hmm that's very weird. make build and make serve should be near-identical except serve also watches for changes.

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.

@bvaughn
Copy link
Contributor

bvaughn commented Aug 20, 2017

Fetched and pulled and make serve is behaving now.

Copy link
Contributor

@bvaughn bvaughn left a 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.

className: ?string,
};

const PresetLoadingAnimation = ({ className }: PresetLoadingAnimationProps) =>
Copy link
Contributor

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;
}
Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

🤡

paddingRight: "1.5rem",

[media.large]: {
borderTop: "2px solid #121417",
Copy link
Contributor

Choose a reason for hiding this comment

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

Subjective nit: Not a big fan of the top border. Wondering if you considered a different background color instead, to make this section stand out?

background-color: #181a1f;

screen shot 2017-08-20 at 8 47 37 am

"evaluate",
"lineWrap",
"presets",
"prettier",
"showSidebar",
"targets",
"targets",
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Great comment!

Copy link
Member

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. 😛

if (!artifacts || artifacts.length === 0) {
alert(
`Could not find valid babel-standalone artifact in build #${build}`
);
Copy link
Contributor

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?

Copy link
Member Author

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.

};

xhr.onerror = function() {
alert(`Could not load Babel build #${build} :(`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto as above.

@@ -0,0 +1,39 @@
export default function loadBuildArtifacts(
repo: string = "babel/babel",
Copy link
Contributor

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.)

@existentialism
Copy link
Member Author

@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).

@bvaughn
Copy link
Contributor

bvaughn commented Aug 21, 2017

add an error icon instead of sad face emoji

Love it 😁 Happy to help with this

const PresetLoadingAnimation = ({
className = "",
}: PresetLoadingAnimationProps) =>
<div className={`${className || ""} ${styles.loadingAnimation}`}>
Copy link
Contributor

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) {
Copy link
Contributor

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();
Copy link
Contributor

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);
Copy link
Member

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?)

Copy link
Member

@Daniel15 Daniel15 left a 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!

@existentialism existentialism merged commit 55454fd into master Aug 22, 2017
@existentialism existentialism deleted the issue1313 branch August 22, 2017 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants