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

Keep stylesLoaded out of global context #4194

Closed
wants to merge 2 commits into from

Conversation

swiftMessenger
Copy link
Contributor

Moved the dialog plugin's stylesLoaded variable into the IIFE to prevent the stylesLoaded variable from being included (and editable) in the global context. This also required moving the "CKEDITOR.plugins.add( 'dialog', { ..." call into the IIFE - where it should have been to begin with.

What is the purpose of this pull request?

Bug fix. The stylesLoaded variable referenced by the dialog plugin was placed on the global scope, which creates two major issues:

  1. It could interfere with other scripts attempting to utilize a variable of the same name on the global scope thereby creating bugs in other code.
  2. Other scripts could easily accidentally change the value of the scriptsLoaded variable, potentially causing the dialog styles to be loaded multiple times if multiple editors are present.

Does your PR contain necessary tests?

This PR does NOT contain tests. The ideal test should check for the existence of ANY non-essential global variables after fully loading CKEditor (including all plugins and non-core code) - passing if there are none and failing if there are any. This may need to be a manual test for now

This PR contains

  • 0 Unit tests
  • 0 Manual tests

Did you follow the CKEditor 4 code style guide?

PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

Moved stylesLoaded variable out of the global context

What changes did you make?

Moved all relevant code for the dialog plugin into the IIFE to prevent global context contamination.

Which issues does your PR resolve?

Unknown if it closes any existing issues. This was just an issue caught by my local testing and it was easy to fix so I created a PR for it.

Moved the dialog plugin's stylesLoaded variable into the IIFE to prevent the stylesLoaded variable from being included (and editable) in the global context. This also required moving the "CKEDITOR.plugins.add( 'dialog', { ..." call into the IIFE - where it should have been to begin with.
Moved comment out of IIFE back to where it belongs
@swiftMessenger swiftMessenger marked this pull request as ready for review August 7, 2020 17:16
@jacekbogdanski jacekbogdanski self-assigned this Aug 14, 2020
@jacekbogdanski jacekbogdanski self-requested a review August 14, 2020 14:14
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

Thanks @swiftMessenger for the contribution!

Indeed, stylesLoaded variable has been polluting global namespace. Could you add a unit test confirming that the variable is no longer accessible from the global scope? You can read more about CKEditor 4 testing environment in dedicated docs article.

if ( !stylesLoaded ) {
CKEDITOR.document.appendStyleSheet( this.path + 'styles/dialog.css' );
stylesLoaded = true;

Copy link
Member

Choose a reason for hiding this comment

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

It seems like there are some trailing spaces, could you remove it?

@jacekbogdanski
Copy link
Member

@swiftMessenger since there is no response for some time already, I've taken over this PR - #4263

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

2 participants