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

Allow adding attributes to import of scripts and styles #848

Closed
muuvmuuv opened this issue Jul 12, 2018 · 9 comments
Closed

Allow adding attributes to import of scripts and styles #848

muuvmuuv opened this issue Jul 12, 2018 · 9 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. help wanted Asking for outside help and/or contributions to this particular issue or PR.

Comments

@muuvmuuv
Copy link
Contributor

🐛 Bug Report

I get an error when loading scripts from a CDN because there is no hash set to the CDN Url. This could be fixed by giving more options to the scripts-array in the config:

Additionally this would add support for async and deferattributes

const config = {
  scripts: [
    {
      src: "https://cdnjs.cloudflare.com/ajax/libs/featherlight/1.7.13/featherlight.min.js",
      integrity: "sha256-/SEQTcl9tvyYDA8SuhV/PMn92shN3kNn8C9vnbBcE9Y=",
      crossorigin: "anonymous",
      async: true
    },
    "../js/theme.js",
  ]
};

Have you read the Contributing Guidelines on issues?

yes

To Reproduce

  1. new Docusaurus
  2. add CDN script
  3. run locally
  4. see the console

Expected behaviour

no error in the console

(Write what you thought would happen.)

Actual Behavior

Error in the console:

Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src https:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

(Write what happened. Add screenshots, if applicable.)

Reproducible Demo

https://hastebin.com/elawucenon.js

@endiliey endiliey added bug An error in the Docusaurus core causing instability or issues with its execution help wanted Asking for outside help and/or contributions to this particular issue or PR. good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. labels Jul 13, 2018
@helloworld
Copy link
Contributor

@muuvmuuv I can't reproduce the issue using your example scripts (they all load as expected), but this is still a good feature to have.

@endiliey can I claim this? I think a simple check of if source is an Object, and simply spreading the object key/values as attributes would be sufficient, unless you would prefer whitelisting only the valid script tag attributes.

this.props.config.scripts.map(source => {
  if (source instanceof Object) {
    return <script type="text/javascript" key={source.src} {...source} />;
  }

  return <script type="text/javascript" key={source} src={source} />;
});

@yangshun
Copy link
Contributor

@helloworld it's yours!

I've added an "issue-claimed" label so that others will know not to start work on the issue. If you change your mind about the issue, no worries! Just let me know so that I can remove the label and free it up for someone else to claim.

I'll check in with you periodically so that we can keep the task updated with the progress.

@yangshun yangshun added the status: claimed Issue has been claimed by a contributor who plans to work on it. label Jul 21, 2018
@muuvmuuv
Copy link
Contributor Author

@helloworld maybe it is just a problem of my local running environment. But yes would anyway a good feature. I‘m looking forward to see this in the next updates

Sent with GitHawk

@endiliey
Copy link
Contributor

@helloworld still working on this ?

@endiliey endiliey removed the status: claimed Issue has been claimed by a contributor who plans to work on it. label Aug 28, 2018
@endiliey
Copy link
Contributor

endiliey commented Sep 1, 2018

@wszgxa sure 👍. Send a PR in

@yangshun
Copy link
Contributor

yangshun commented Sep 2, 2018

@wszgxa it's yours!

I've added an "issue: claimed" label so that others will know not to start work on the issue. If you change your mind about the issue, no worries! Just let me know so that I can remove the label and free it up for someone else to claim.

I'll check in with you periodically so that we can keep the task updated with the progress.

@ravennasoftware
Copy link

ravennasoftware commented Oct 12, 2018

@endiliey This appears to be available again. Can I snag it? Should have some time this weekend.

@endiliey
Copy link
Contributor

@ravennasoftware, sure.

Send a PR in. Best asap so we can release 1.5 along with it

@endiliey
Copy link
Contributor

My bad. #937 should have closed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. help wanted Asking for outside help and/or contributions to this particular issue or PR.
Projects
None yet
Development

No branches or pull requests

5 participants