You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Bug Report: 6.0] Nested components and views may cause rootValue miscalculated (root in Once Event and decl in Declaration Event may be different)
#103
Open
zhaojjiang opened this issue
Nov 25, 2023
· 1 comment
When project is complex enough, there will be nested views and components.
The event order can be Parent-Once --> Children-Once --> Children-Declaration --> Parent-Declaration, which result the rootValue miscalculated from function and so is rem.
I tried many times, and this problem happened many times, but I cannot provide a minimum code to stably reproduce it.
I have noticed there is runtime-defined listeners prepare in postcss may help solve this problem, and tried in another private project which can reproduce this problem. It works. The code like below. Move events wrapped by prepare().
I don't if this logic is right, so just leave it here. In my project, I will just downgrade package to 5.x in a short peried of time to avoid this problem.
module.exports=(options={})=>{convertLegacyOptions(options);constopts=Object.assign({},defaults,options);constsatisfyPropList=createPropListMatcher(opts.propList);constexclude=opts.exclude;return{postcssPlugin: "postcss-pxtorem",prepare(result){// console.log(result);letisExcludeFile=false;letpxReplace;return{Once(css){// console.log('once--------', css.source.input.file);constfilePath=css.source.input.file;if(exclude&&((type.isFunction(exclude)&&exclude(filePath))||(type.isString(exclude)&&filePath.indexOf(exclude)!==-1)||filePath.match(exclude)!==null)){isExcludeFile=true;}else{isExcludeFile=false;}constrootValue=typeofopts.rootValue==="function"
? opts.rootValue(css.source.input)
: opts.rootValue;// console.log(css.source.input.file, rootValue);pxReplace=createPxReplace(rootValue,opts.unitPrecision,opts.minPixelValue);},Declaration(decl){// console.log('decl', decl.source.input.file);if(isExcludeFile)return;if(decl.value.indexOf("px")===-1||!satisfyPropList(decl.prop)||blacklistedSelector(opts.selectorBlackList,decl.parent.selector))return;constvalue=decl.value.replace(pxRegex,pxReplace);// if rem unit already exists, do not add or replaceif(declarationExists(decl.parent,decl.prop,value))return;if(opts.replace){decl.value=value;}else{decl.cloneAfter({value: value});}},AtRule(atRule){if(isExcludeFile)return;if(opts.mediaQuery&&atRule.name==="media"){if(atRule.params.indexOf("px")===-1)return;atRule.params=atRule.params.replace(pxRegex,pxReplace);}}}},};};
The text was updated successfully, but these errors were encountered:
zhaojjiang
changed the title
[Bug Report] root in Once Event and decl in Declaration Event may be different
[Bug Report: 6.0] Nested components and views may cause rootValue miscalculated (root in Once Event and decl in Declaration Event may be different)
Nov 25, 2023
When project is complex enough, there will be nested views and components.
The event order can be Parent-Once --> Children-Once --> Children-Declaration --> Parent-Declaration, which result the rootValue miscalculated from function and so is rem.
I tried many times, and this problem happened many times, but I cannot provide a minimum code to stably reproduce it.
I have noticed there is runtime-defined listeners
prepare
in postcss may help solve this problem, and tried in another private project which can reproduce this problem. It works. The code like below. Move events wrapped byprepare()
.I don't if this logic is right, so just leave it here. In my project, I will just downgrade package to 5.x in a short peried of time to avoid this problem.
The text was updated successfully, but these errors were encountered: