Fix #1734 out-of-order loading of external CSS resource

This commit is contained in:
Kijin Sung 2021-07-01 14:36:35 +09:00
parent 4c4596d659
commit d78ba8c77c
3 changed files with 33 additions and 13 deletions

View file

@ -79,7 +79,7 @@ class FrontEndFileHandler extends Handler
* case css
* $args[0]: file name
* $args[1]: media
* $args[2]: target IE
* $args[2]: target IE / source type hint
* $args[3]: index
* $args[4]: vars for LESS and SCSS
* </pre>
@ -114,6 +114,16 @@ class FrontEndFileHandler extends Handler
}
}
if (preg_match('/IE/i', $args[2]))
{
$source_hint = '';
}
else
{
$source_hint = $args[2];
$args[2] = '';
}
$file = $this->getFileInfo($args[0], $args[2] ?? '', $args[1] ?? 'all', $args[4] ?? [], $isCommon);
$file->index = (int)($args[3] ?? 0);
@ -128,7 +138,7 @@ class FrontEndFileHandler extends Handler
$map = &$this->cssMap;
$mapIndex = &$this->cssMapIndex;
$this->_arrangeCssIndex($file->fileRealPath, $file);
$this->_arrangeCssIndex($file->fileRealPath, $file, $source_hint);
}
else if($file->fileExtension == 'js')
{
@ -701,24 +711,32 @@ class FrontEndFileHandler extends Handler
*
* @param string $dirname
* @param object $file
* @param string $hint
* @return void
*/
protected function _arrangeCssIndex($dirname, $file)
protected function _arrangeCssIndex($dirname, $file, $hint = '')
{
if ($file->index < -100000)
{
return;
}
$dirname = substr($dirname, strlen(\RX_BASEDIR));
if (strncmp($dirname, self::$assetdir . '/', strlen(self::$assetdir) + 1) === 0)
if ($hint)
{
$dirname = substr($dirname, strlen(self::$assetdir) + 1);
$tmp = $hint;
}
else
{
$dirname = substr($dirname, strlen(\RX_BASEDIR));
if (strncmp($dirname, self::$assetdir . '/', strlen(self::$assetdir) + 1) === 0)
{
$dirname = substr($dirname, strlen(self::$assetdir) + 1);
}
$tmp = array_first(explode('/', strtr($dirname, '\\.', '//')));
}
$tmp = array_first(explode('/', strtr($dirname, '\\.', '//')));
if ($tmp)
{
$cssSortList = array('common' => -100000, 'layouts' => -90000, 'modules' => -80000, 'widgets' => -70000, 'addons' => -60000);
$cssSortList = array('common' => -100000, 'layouts' => -90000, 'm.layouts' => -90000, 'modules' => -80000, 'widgets' => -70000, 'addons' => -60000);
$file->index += isset($cssSortList[$tmp]) ? $cssSortList[$tmp] : 0;
}
}

View file

@ -16,6 +16,7 @@ class TemplateHandler
private $file = NULL; ///< target file (fullpath)
private $web_path = NULL; ///< tpl file web path
private $compiled_file = NULL; ///< tpl file web path
private $source_type = NULL;
private $config = NULL;
private $skipTags = NULL;
private $handler_mtime = 0;
@ -75,9 +76,9 @@ class TemplateHandler
$this->filename = null;
$this->file = null;
$this->compiled_file = null;
$this->source_type = null;
$this->config = new stdClass;
$this->skipTags = null;
$this->compiled_file = null;
self::$rootTpl = null;
}
@ -121,6 +122,7 @@ class TemplateHandler
// set compiled file name
$converted_path = ltrim(str_replace(array('\\', '..'), array('/', 'dotdot'), $tpl_file), '/');
$this->compiled_file = \RX_BASEDIR . 'files/cache/template/' . $converted_path . '.php';
$this->source_type = preg_match('!^((?:m\.)?[a-z]+)/!', $tpl_path, $matches) ? $matches[1] : null;
}
/**
@ -874,7 +876,7 @@ class TemplateHandler
{
$metafile = isset($attr['target']) ? $attr['target'] : '';
$result = vsprintf("Context::loadFile(['%s', '%s', '%s', '%s']);", [
$attr['target'] ?? '', $attr['type'] ?? '', $attr['targetie'] ?? '', $attr['index'] ?? '',
$attr['target'] ?? '', $attr['type'] ?? '', $attr['targetie'] ?? ($isRemote ? $this->source_type : ''), $attr['index'] ?? '',
]);
}
break;
@ -892,7 +894,7 @@ class TemplateHandler
$metafile = isset($attr['target']) ? $attr['target'] : '';
$metavars = isset($attr['vars']) ? ($attr['vars'] ? self::_replaceVar($attr['vars']) : '') : '';
$result = vsprintf("Context::loadFile(['%s', '%s', '%s', '%s', %s]);", [
$attr['target'] ?? '', $attr['media'] ?? '', $attr['targetie'] ?? '', $attr['index'] ?? '',
$attr['target'] ?? '', $attr['media'] ?? '', $attr['targetie'] ?? ($isRemote ? $this->source_type : ''), $attr['index'] ?? '',
isset($attr['vars']) ? ($attr['vars'] ? self::_replaceVar($attr['vars']) : '[]') : '[]',
]);
}