Fix module JS config initialisation on AJAX request (#7225)

This commit is contained in:
Yuriy Bakhtin 2024-09-24 10:10:28 +03:00 committed by GitHub
parent a4a4293da3
commit acddf8736c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -9,6 +9,7 @@ HumHub Changelog
- Fix #7219: Renamed deprecated meta tag
- Fix #7174: In lists, when an item text is displayed on multiple lines, the lines below are not lining up with the first one
- Fix #7222: Fix rendering of checkbox on MacOS and iOS
- Fix #7225: Fix module JS config initialisation on AJAX request
1.16.2 (September 5, 2024)
--------------------------

View File

@ -521,7 +521,15 @@ class View extends \yii\web\View
protected function flushJsConfig($key = null)
{
if (!empty($this->jsConfig)) {
$this->registerJs("humhub.config.set(" . json_encode($this->jsConfig) . ");", View::POS_BEGIN, $key);
$jsConfig = 'humhub.config.set(' . json_encode($this->jsConfig) . ')';
if (Yii::$app->request->isAjax) {
// This fix is required only on AJAX request!
// Put JS config code into the "jsFiles" array, in order to call it before
// the module JS file where the config must be already initialised.
$this->jsFiles[self::POS_HEAD][$key ?: md5($jsConfig)] = Html::script($jsConfig);
} else {
$this->registerJs($jsConfig, self::POS_BEGIN, $key);
}
$this->jsConfig = [];
}
}