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

added automatically loading the default esri's css stylesheet #80

Merged
merged 2 commits into from
Feb 7, 2018

Conversation

SimplyAutomationized
Copy link

found useful to load the default css stylesheet automatically

Copy link
Member

@tomwayson tomwayson left a comment

Choose a reason for hiding this comment

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

Thank you @SimplyAutomationized!

I don't know if you saw the open issue that we have for this: #6

What you've implemented in this PR is close to what we laid out in that issue as the first iteration of this feature, so I'd like to merge this. However, there are few things that will need to happen before we could release this.

The main change is that I don't think we should load CSS by default. I'd guess that most people actually would like that, especially b/c in this case it's not like the esri styles are available in some other format like Sass that users might want to bring into their app via some other asset pipeline. However, in the even that someone wants to load the styles by some other means, I don't think the API you've created in this PR will allow them to not inject a style <link>. Also, injecting styles by default would be a breaking change and require a major version bump.

I've made some line comments suggesting changes to make injecting the styles completely optional. In addition to those, we would need to

  • document how to use this in the README
  • write additional tests that verify that the style tag is not injected by default and is injected when you pass the css option
  • update the Unreleased section of the changelog

Please let me know how much, if any, of that you are up for and either myself or @jwasilgeo will be available to help.

Thanks again for your contribution!

@@ -12,7 +12,7 @@
*/
const isBrowser = typeof window !== 'undefined';
const DEFAULT_URL = 'https://js.arcgis.com/4.6/';

const DEFAULT_CSS = 'https://js.arcgis.com/4.6/esri/css/main.css';
Copy link
Member

Choose a reason for hiding this comment

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

Remove this, it won't be needed since we're not loading styles by default.

@@ -72,7 +80,9 @@ export const utils = {
export function getScript() {
return document.querySelector('script[data-esri-loader]') as HTMLScriptElement;
}

export function getCss() {
return document.querySelector('style[data-esri-loader]') as HTMLStyleElement;
Copy link
Member

Choose a reason for hiding this comment

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

I think this would actually be a HTMLLinkElement

options.url = DEFAULT_URL;
options.url = DEFAULT_URL;
}
if (!options.css) {
Copy link
Member

Choose a reason for hiding this comment

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

Remove this, we only want to load styles if the options.css was passed in.

}

return new utils.Promise((resolve, reject) => {
let script = getScript();
let cssLib = getCss();
Copy link
Member

Choose a reason for hiding this comment

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

this is not used, it probably should be removed.

@@ -119,6 +133,7 @@ export function loadScript(options: ILoadScriptOptions = {}): Promise<HTMLScript
}
// create a script object whose source points to the API
script = createScript(options.url);
cssLib = createCssLib(options.css);
Copy link
Member

Choose a reason for hiding this comment

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

this line and the document.body.appendChild(cssLib); line below should only be executed if options.css was passed in. So:

if (!options.css) {
  document.body.appendChild(createCssLib(options.css));
}

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "esri-loader",
"version": "2.0.0",
"version": "2.1.0",
Copy link
Member

@tomwayson tomwayson Jan 19, 2018

Choose a reason for hiding this comment

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

This will need to be reverted - the it will be handled by our release script. Generally it's a good idea to leave version bumps out of PRs.

@tomwayson
Copy link
Member

After thinking about it, if we really think that most people will want loadScript() to lazily inject the <link> tag when it injects the <script> tag, we should probably do that by default rather than make people pass the url to the css - even if that's a breaking change.

We'd still have to change the API defined in this PR so that it allows people load the styles by other means. I haven't put much thought in this yet, but I'm not a big fan of css: false b/c I don't like explicitly checking for false, but I don't have a better idea yet. I'm open to suggestion.

@jwasilgeo
Copy link
Contributor

Thanks @SimplyAutomationized for sharing your contribution.

I agree with the code review and PR housekeeping requests above, @tomwayson. I began to write too much here, so I'm going to move my comments over to issue thread #6.

- reverted version
- added changes changelog [Unreleased]
- check if the stylesheet has been added manually.
@SimplyAutomationized
Copy link
Author

after your second thoughts do you still want to remove
const DEFAULT_CSS = 'https://js.arcgis.com/4.6/esri/css/main.css';
I added some checks with the getCss(url) method it checks for any link elements containing url or 'esri/themes/' or the url.

export function getCss(url) {
  return document.querySelector(`link[href*="${url}"], link[href*="/esri/themes/"`) as HTMLLinkElement;
}

thoughts?

@tomwayson
Copy link
Member

tomwayson commented Jan 24, 2018

@SimplyAutomationized thanks for following up w/ the changes. They look good.

I still haven't had time to think about what we'll eventually want the API to be for this.

In the mean time, I'd like to land your commits into incremental, non-breaking changes so that people can start benefiting from them sooner than later and we can hash out an API over time.

I haven't put much thought into this, but it seems like the minimally viable, non-breaking API would be to export a new function called loadCss(url) that would call the code you've added to load the <link> tag. That should be fairly easy to release (i.e. w/ tests and documentation).

From there we can think about how to be smart about how we can automagically ✨ call that new function from loadScript()/loadModules() function and how to default to the right url based on the url of script tag, etc.

I'm pretty swamped right now and don't have time to give more direction that that. If you or @jwasilgeo feel like that makes sense and can run w/ that, great. Otherwise, I'll make a new branch based on yours and give it a go when I get a chance.

@jwasilgeo
Copy link
Contributor

jwasilgeo commented Jan 24, 2018

Seems like a good plan to me.

...it seems like the minimally viable, non-breaking API would be to export a new function called loadCss(url) that would call the code you've added to load the tag. That should be fairly easy to release (i.e. w/ tests and documentation).

How does that sound to you, @SimplyAutomationized? I can help out.

@tomwayson tomwayson mentioned this pull request Feb 5, 2018
@tomwayson tomwayson merged commit c99974e into Esri:master Feb 7, 2018
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.

None yet

3 participants