Needs work
Project:
Asset Injector
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Sep 2019 at 23:48 UTC
Updated:
22 Nov 2025 at 00:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
pookmish commentedI understand the issue, but since the request is a bit of a rare scenario, I'm leaning towards relying on modules/themes to modify the library by either inserting the css & JavaScript to disable Ace editor. Or override it to provide a local copy of Ace editor with the respective module/theme.
Comment #3
pookmish commentedComment #4
bkosborneI wonder if you'd re-consider this. Any site that uses a content security policy to only allow specific JS sources will run into problems with this. A simple UI config setting to specify a path override for the ACE JS source would suffice. If you leave this open, I will eventually get time to contribute a patch for it.
Comment #5
geek-merlin> I'm leaning towards relying on modules/themes to modify the library ... to provide a local copy.
FTR: I rolled Asset Fetcher for this purpose, but it's not battle tested. please test and review.
Comment #6
pookmish commented@bkosborne feel free to reopen this if you produce a patch.
As a thought, a workaround similar to the patch would be to just use asset injector to load the ace library for you. Copy and paste the ace library into an injector and add it to the UI page. It's a hacky way to produce the same results.
Comment #7
Jonny Gong commentedHi, I made a patch for this.
Introduced the ace editor in the module and modified the reference path to ace.js.
Tested on version 8.x-2.7, it works for me.
Comment #8
Jonny Gong commentedComment #9
pookmish commentedThanks Jonny, I like the direction you are thinking. Since `respositories` only work at the root level of composer.json, I think we could go the direction of a suggested package.
Then using the `hook_library_info_alter()` detect if the ace library exists locally and adjust the existing library definition. That approach would then not affect any existing site that works fine with CDN use but allow for this scenario to be satisfied.
Comment #10
pookmish commentedComment #11
Jonny Gong commented@pookmish
Sorry, i have no time to do this for now. If i have time or any guys can help, please.
This patch fixed issue that Drupal asset aggregation will broken ace mode asset loading.
related issue: https://github.com/ajaxorg/ace/issues/655#issuecomment-7596749
Comment #14
ruslan piskarovIn #13 I have improved the patch provided by @Jonny Gong in #11. Removed "docroot" path, etc. Could you review it?
Comment #15
pookmish commentedThe approach in #13 is very complicated to implement. What I would prefer to see is a
1. composer suggested package of "npm-asset/ace-builds" (the same package that ace editor module uses. That way it doesn't duplicate packages in the codebase.
2. since the ace editor package would then be suggested and optional, produce a hook_libraries_alter that changes the path of the ace editor to use the local path if available.
Using the approach I outlined above will prevent any breaking changes for existing users and provide the ability to simply require a new package and then ace editor would be hosted locally.
Comment #16
ruslan piskarovComment #17
randy tang commentedComment #18
anybodyI agree this needs a more simple and general rewrite. Please have a look at this issue and MR for reference:
#3214406: Add option to host dragula library locally
https://git.drupalcode.org/project/layout_paragraphs/-/merge_requests/70
If the library can't be loaded locally (from /libraries folder), it falls back to the CDN version. The MR also contains tests, etc. and the approach is well tested in Webform, so I'd rate that as best practice.
Would someone like to implement the same here as new MR?
Comment #19
tobiasbThe patch is just a updated version.
Comment #20
anybodyComment #21
geek-merlin#18: Yes!
Comment #22
bkosborneHmm I think it goes beyond just replacing the library path to load from a local version instead of the CDN, because the this module's
asset_injector.ace_editor.jscurrently includes the following hardcoded:I think these three lines are only necessary if you're loading it from the CDN. This can probably be solved if we pass down via drupalSettings if the module used the CDN or not to load the main library, and if not, don't run these lines.
Comment #23
bkosborneOkay, I was wrong, we need those lines regardless, because without them the library tries to auto-detect the path to those directories and it doesn't work if JS aggregation is turned on.
So, if the ace-builds version of the library is used (and stored locally), we need to provide its path via drupalSettings
Comment #24
tobiasbI updated the MR for the latest changes.
Comment #25
tobiasbComment #26
anybodyThanks @tobiasb - the README says
but I can't see related code, what am I missing?
Also see #18 - looks like hook_library_info_alter() and other parts like the tests are still missing?
The referenced issue is a nice template.
Comment #27
tobiasbTherefore it was "needs work". :d
Comment #28
anybodyWasn't :P
See #25 + #26
Eventually by accident ;) All good
Comment #29
danielehrenhoferDue to our content security policy, loading external resources, e.g. via a CDN, is prohibited. As a result, I have now noticed that ace.js appears to be loading the resource mode-css.js via a CDN: https://cdnjs.cloudflare.com/ajax/libs/ace/1.8.1/mode-css.js
Is this known and can it be prevented somehow?
For better illustration I have added a screenshot of my developer console.
Comment #30
tobiasbSaw the same.
ace.config.setwas overridden by the old way, onlyworkerPathworkedI replaced it and updated to latest version.
Comment #31
tobiasbComment #32
konfuzed commentedMinor update to https://github.com/ajaxorg/ace-builds/archive/refs/tags/v1.43.4.zip locally worked on the patch in #31