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

Introduce salesforcedx-webview-ui package #451

Merged
merged 18 commits into from
Jun 5, 2018

Conversation

vazexqi
Copy link
Contributor

@vazexqi vazexqi commented May 31, 2018

What does this PR do?

This is the package that will contain all the .html that we will use for each webview. We will use this to create webviews that will be surfaced in VS Code. This will be based on the approach documented at https://code.visualstudio.com/docs/extensions/webview

What issues does this PR fix or reference?

@W-5013822@

@codecov
Copy link

codecov bot commented Jun 1, 2018

Codecov Report

Merging #451 into develop will decrease coverage by 0.5%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #451      +/-   ##
===========================================
- Coverage    76.38%   75.88%   -0.51%     
===========================================
  Files          138      139       +1     
  Lines         5400     5436      +36     
  Branches       845      851       +6     
===========================================
  Hits          4125     4125              
- Misses        1066     1102      +36     
  Partials       209      209
Impacted Files Coverage Δ
...dx-vscode-core/src/webviewPanels/manifestEditor.ts 0% <0%> (ø)
...scode-core/src/decorators/scratch-org-decorator.ts 39.13% <0%> (+3.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 57abc05...73c4449. Read the comment docs.

@@ -0,0 +1,122 @@
# Introduction
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main file that you should read to get the gist of this PR.
The other parts I will illustrate to the team via an internal demo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lcampos - Would appreciate your thoughts on this.

We can still merge this in and we can continue the discussion later but it would be appreciated if you could share some thoughts on this based on your work with sutro - I'm not sure if you were using webviews there (or browserview).

Either way, the links in the README.md should be useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did look at using webviews but I was able to make it work by using TextDocumentContentProvider to render my html/js. I didn't need to modify anything outside of the html/js files I was rendering.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, seems WebViews is the "new" way to go based on this https://code.visualstudio.com/updates/v1_21#_webview-api

@vazexqi vazexqi force-pushed the nick/add-salesforcedx-webview-ui-package branch from 446a2b0 to c9689fe Compare June 2, 2018 01:11
@vazexqi vazexqi requested a review from lcampos June 4, 2018 15:52

* [`<webview>` Tag](https://electronjs.org/docs/api/webview-tag)
* [Interop’s Labyrinth: Sharing Code Between Web & Electron Apps](https://slack.engineering/interops-labyrinth-sharing-code-between-web-electron-apps-f9474d62eccc)
* [Growing Pains: Migrating Slack’s Desktop App to BrowserView](https://slack.engineering/growing-pains-migrating-slacks-desktop-app-to-browserview-2759690d9c7b)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are some bugs with webview in Electron. See https://github.com/electron/electron/issues?q=is%3Aopen+is%3Aissue+label%3Acomponent%2Fwebview

However, I searched on the VS Code repo and there were no discussions about considering using BrowserView instead of WebView. So that option doesn't seem to exist for VS Code.


# Developer Flow

## Rapid Iteration of the UI
Copy link
Contributor

Choose a reason for hiding this comment

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

This is currently just showing me a blank page, is it expected ? I do see the manifest editor when I run the extensions tho.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

That was it, thanks

// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
loader: require.resolve('file-loader'),
Copy link
Contributor

@lcampos lcampos Jun 5, 2018

Choose a reason for hiding this comment

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

Did you try something like
{ test: /.(jpe?g|png|gif|svg|woff|eot|ttf)$/i, loader: 'file-loader?name=/media/[name].[ext]' }
? I have it working like that in another project but it might be because I'm on a more recent version of file-loader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will try. I wasn't sure if you could pack svg|woff|eot|ttf. That would help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I might be misunderstanding here but this should be OK because this is the last branch of the oneOf branch. That means we shouldn't need to add more tests. In fact, this test is the not of the other branches.

So, we are already serving the svg, woff, eot, and ttf files. For jpeg, png, gif we actually convert embed them as data URLS to avoid any requests. See

// "url" loader works like "file" loader except that it embeds assets
and https://webpack.js.org/loaders/url-loader/

What I've done is also add woff|eot|ttf so that they get embedded.

I verified that we must be serving them properly because blueprint.js uses some custom font for the icons and we are seeing those icons in the manifest editor.

"engines": {
"vscode": "^1.17.0"
},
"dependencies": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Everything webpack, loaders, jest etc should be under devDependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. I got this from create-react-app. This was the section that they put it in. I can move them into dev-dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it depends on how we are bundling the extension, are we keeping them as part of node_modules when creating the extension?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, we only bundle the stuff that is optimized in the /build folder. So nothing from node_modules leaks in. Everything has to be bundled in a way that you can just load the .html/.js/etc. All the JS is bundled as UMD, not That's why I think it's OK and that is why create-react-app did it that way. I will investigate more but I don't think I change this from how they were doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm looking at https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/package.json and https://github.com/wmonk/create-react-app-typescript/blob/master/packages/react-scripts/package.json

It seems that react, react-dom, and typescript are in the devDependencies. Let me move those back in there to follow that (not sure how it got moved into dependencies).

I will keep webpack and rest in dependencies for now since that seems to be how the template it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"tslint-react": "3.2.0",
"uglifyjs-webpack-plugin": "1.1.8",
"url-loader": "0.6.2",
"webpack": "3.8.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

@@ -0,0 +1,6 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
Copy link
Contributor

Choose a reason for hiding this comment

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

We should change this to import { render } from 'react-dom'; so it will only import the render method and nothing else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't the tree shaking and dead-code elimination from webpack solve the issue of bringing too much? Or am I overestimating what it can do?

Copy link
Contributor

Choose a reason for hiding this comment

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

Tree shaking will remove that, but I didn't see anything for that on the webpack config files. Is babel compiling to ES6? If it is then webpack will automatically do tree shaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like we are still compressing/outputting to ecma5. Let me get it into ecma 6. We should use es6 to be consistent with the rest of the output from vs code.

I see now that tree shaking is only enabled for es6 or es2015. https://webpack.js.org/guides/tree-shaking/

@vazexqi vazexqi force-pushed the nick/add-salesforcedx-webview-ui-package branch from db9c92e to 23bf1c2 Compare June 5, 2018 20:25
@vazexqi
Copy link
Contributor Author

vazexqi commented Jun 5, 2018

@lcampos - The current version of create-react-app uses webpack 3.8.1 and not webpack 4 yet. We can decide to update this later if needed. I can't find an official upgrade doc like I could for webpack 2 -> 3 (https://webpack.js.org/migrate/3/)

@vazexqi vazexqi merged commit 8da30f8 into develop Jun 5, 2018
@vazexqi vazexqi deleted the nick/add-salesforcedx-webview-ui-package branch June 5, 2018 22:55
@lcampos
Copy link
Contributor

lcampos commented Jun 6, 2018

@vazexqi there's not migration guide yet but there's some progress being made and tracked here (webpack/webpack.js.org#1706). Right now, unless we see build/bundle perf issues I'd say we can wait to move to v4.

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.

2 participants