@@ -51,7 +51,11 @@ function getOrder(prepend?: Prepend): AppendType {
5151/**
5252 * Find style which inject by rc-util
5353 */
54- function findStyles ( container : ContainerType ) {
54+ function findStyles ( container : ContainerType | null ) {
55+ if ( ! container ) {
56+ return [ ] ;
57+ }
58+
5559 return Array . from (
5660 ( containerCache . get ( container ) || container ) . children ,
5761 ) . filter ( node => node . tagName === 'STYLE' ) as HTMLStyleElement [ ] ;
@@ -79,6 +83,10 @@ export function injectCSS(css: string, option: Options = {}) {
7983 styleNode . innerHTML = css ;
8084
8185 const container = getContainer ( option ) ;
86+ if ( ! container ) {
87+ return null ;
88+ }
89+
8290 const { firstChild } = container ;
8391
8492 if ( prepend ) {
@@ -132,7 +140,7 @@ export function removeCSS(key: string, option: Options = {}) {
132140 const existNode = findExistNode ( key , option ) ;
133141 if ( existNode ) {
134142 const container = getContainer ( option ) ;
135- container . removeChild ( existNode ) ;
143+ container ? .removeChild ( existNode ) ;
136144 }
137145}
138146
@@ -145,6 +153,10 @@ function syncRealContainer(container: ContainerType, option: Options) {
145153 // Find real container when not cached or cached container removed
146154 if ( ! cachedRealContainer || ! contains ( document , cachedRealContainer ) ) {
147155 const placeholderStyle = injectCSS ( '' , option ) ;
156+ if ( ! placeholderStyle ) {
157+ return ;
158+ }
159+
148160 const { parentNode } = placeholderStyle ;
149161 containerCache . set ( container , parentNode ) ;
150162 container . removeChild ( placeholderStyle ) ;
@@ -164,6 +176,10 @@ export function updateCSS(
164176 originOption : Options = { } ,
165177) {
166178 const container = getContainer ( originOption ) ;
179+ if ( ! container ) {
180+ return null ;
181+ }
182+
167183 const styles = findStyles ( container ) ;
168184 const option = { ...originOption , styles } ;
169185
@@ -185,6 +201,10 @@ export function updateCSS(
185201 }
186202
187203 const newNode = injectCSS ( css , option ) ;
204+ if ( ! newNode ) {
205+ return null ;
206+ }
207+
188208 newNode . setAttribute ( getMark ( option ) , key ) ;
189209 return newNode ;
190210}
0 commit comments