When the system.css_js_query_string value gets reset, it avoids having to hard-clear my browser's cached files in order to get updated JS. However, CKEditor uses its own cache-busting string, and the scripts loaded by CKEditor can get out of date when doing a deployment. It would be good to force CKEditor to re-use the same string.

Related issues:
ckeditor.module (for D7): #2679179: CKEditor uses separate cache-busting query string from Drupal's
wysiwyg.module (for D7): #2679106: CKEditor uses separate cache-busting query string from Drupal's

Comments

Dave Reid created an issue. See original summary.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new1.84 KB
wim leers’s picture

Nice! I never even thought about this, nor has it come up at all in the past few years. Even better integration between Drupal 8 and CKEditor.

Thank you very much! :)

Manually tested, works perfectly. Ideally this would get test coverage, but I'm not sure it's worth it in this case.

  1. +++ b/core/modules/ckeditor/ckeditor.module
    @@ -100,3 +100,14 @@ function _ckeditor_theme_css($theme = NULL) {
    +  // Pass Drupal's JS cache-busting string via settings along to CKEditor.
    

    Let's link to http://docs.ckeditor.com/#!/api/CKEDITOR-property-timestamp

  2. +++ b/core/modules/ckeditor/ckeditor.module
    @@ -100,3 +100,14 @@ function _ckeditor_theme_css($theme = NULL) {
    +  if ($extension == 'ckeditor' && isset($libraries['drupal.ckeditor'])) {
    

    I prefer strict equality.

  3. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -273,4 +273,19 @@
    +  Drupal.behaviors.ckeditor = {
    +    attach: function (context, settings) {
    +      // Manually set the cache-busting string to the same value as Drupal.
    +      CKEDITOR.timestamp = settings.ckeditor.timestamp;
    +    }
    +  };
    

    In Drupal 8, the fact that core/ckeditor now has a dependency on core/drupalSettings means that drupalSettings are *guaranteed* to be loaded before core/modules/ckeditor/js/ckeditor.js. Hence this does not need to happen in a Drupal behavior.

    So then it becomes just:

    CKEDITOR.timestamp = drupalSettings.ckeditor.timestamp
    

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

Status: Needs review » Needs work
wim leers’s picture

Issue tags: +Needs tests

Actually, this should be quite straightforward to test:

  1. Assert using $this->drupalGetSettings() that the setting sent with the page matches the current query string
  2. Do something that calls drupal_flush_all_caches()
  3. Assert it still matches
wim leers’s picture

Issue tags: +Novice, +php-novice
thpoul’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.08 KB
new3.1 KB

Here is a first test.

wim leers’s picture

Status: Needs review » Needs work

Thanks, looks great! Just one question (besides the nits below): could you upload a test-only patch to show that the test indeed fails without the actual changes?

  1. +++ b/core/modules/ckeditor/ckeditor.module
    @@ -108,7 +108,8 @@ function _ckeditor_theme_css($theme = NULL) {
    +  // http://docs.ckeditor.com/#!/api/CKEDITOR-property-timestamp
    

    Missing @see.

  2. +++ b/core/modules/ckeditor/js/ckeditor.js
    @@ -273,19 +273,7 @@
    +  // Manually set the cache-busting string to the same value as Drupal.
    

    s/Manually set the/Set the CKEditor/

  3. +++ b/core/modules/ckeditor/src/Tests/CKEditorLoadingTest.php
    @@ -148,6 +148,16 @@ function testLoading() {
    +    // Remove all caches then make sure that $settings['ckeditor']['timestamp']
    

    s/Remove/Flush/

thpoul’s picture

Status: Needs work » Needs review
StatusFileSize
new1.47 KB

Here is the test only patch, which should fail the test.

thpoul’s picture

StatusFileSize
new2.24 KB
new3.1 KB

And here are the nits :) Thank you for the review Wim!

The last submitted patch, 10: 2679903-test-only-10.patch, failed testing.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect!

  • catch committed adaad5f on 8.2.x
    Issue #2679903 by thpoul, Dave Reid, Wim Leers: CKEditor uses separate...

  • catch committed 391c790 on 8.1.x
    Issue #2679903 by thpoul, Dave Reid, Wim Leers: CKEditor uses separate...
catch’s picture

Version: 8.2.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.2.x and cherry-picked to 8.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

wim leers’s picture

Oops, didn't mean to remove a related issue.