-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
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.
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'; |
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.
Remove this, it won't be needed since we're not loading styles by default.
src/esri-loader.ts
Outdated
@@ -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; |
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 think this would actually be a HTMLLinkElement
src/esri-loader.ts
Outdated
options.url = DEFAULT_URL; | ||
options.url = DEFAULT_URL; | ||
} | ||
if (!options.css) { |
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.
Remove this, we only want to load styles if the options.css
was passed in.
src/esri-loader.ts
Outdated
} | ||
|
||
return new utils.Promise((resolve, reject) => { | ||
let script = getScript(); | ||
let cssLib = getCss(); |
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 is not used, it probably should be removed.
src/esri-loader.ts
Outdated
@@ -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); |
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 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", |
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 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.
After thinking about it, if we really think that most people will want 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 |
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.
after your second thoughts do you still want to remove
thoughts? |
@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 From there we can think about how to be smart about how we can automagically ✨ call that new function from 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. |
Seems like a good plan to me.
How does that sound to you, @SimplyAutomationized? I can help out. |
found useful to load the default css stylesheet automatically