@@ -15,13 +15,14 @@ const walkRules = (root, opts, ruleHandler) => {
1515 containerSelectors . indexOf ( selector ) !== - 1 ;
1616
1717 const handleRule = ( rule , parentCQAtRule ) => {
18+ const definedContainer = hasContainerDefinition ( rule ) ;
1819 const isContainer =
19- hasContainerDefinition ( rule ) ||
20+ definedContainer ||
2021 hasContainerSelector ( rule . selector ) ||
2122 rule . selector === ":self" ||
2223 ( opts . singleContainer && containerSelectors . length === 0 ) ;
2324
24- const data = { rule, isContainer } ;
25+ const data = { rule, isContainer, definedContainer } ;
2526
2627 if ( isContainer && ! hasContainerSelector ( rule . selector ) ) {
2728 containerSelectors . push ( rule . selector ) ;
@@ -103,20 +104,33 @@ function containerQuery(options = {}) {
103104 if ( ! meta ) {
104105 const containers = { } ;
105106 let currentContainerSelector = null ;
107+ let containerDefinitionCount = 0 ;
106108
107109 walkRules (
108110 root ,
109111 { singleContainer } ,
110- ( { rule, isContainer, parentCQAtRule } ) => {
112+ ( { rule, isContainer, definedContainer , parentCQAtRule } ) => {
111113 if (
112114 isContainer &&
113115 rule . selector !== ":self" &&
114116 ! containers [ rule . selector ]
115117 ) {
118+ if ( definedContainer ) {
119+ containerDefinitionCount ++ ;
120+ }
121+
116122 const nextContainerSelector = rule . selector ;
117- if ( singleContainer && currentContainerSelector ) {
123+ if (
124+ // We allow for a single custom definition to be used in
125+ // singleContainer mode so that the user can select the container
126+ // selector themselves, instead that being picked up as the first
127+ // one automatically.
128+ containerDefinitionCount > 1 &&
129+ singleContainer &&
130+ currentContainerSelector
131+ ) {
118132 throw rule . error (
119- `define-container declaration detected in singleContainer mode. ` +
133+ `More than one @ define-container declaration was detected in singleContainer mode. ` +
120134 `Tried to override "${ currentContainerSelector } " with "${ nextContainerSelector } ".`
121135 ) ;
122136 }
0 commit comments