Skip to content

Commit 72e4ed7

Browse files
committed
Remove unused SyntaxRule references and improve error handling in runtime
1 parent 0de4f7f commit 72e4ed7

File tree

9 files changed

+16
-35
lines changed

9 files changed

+16
-35
lines changed

internal

packages/core/src/core.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default class MasterCSS {
3131
readonly variables = new Map<string, Variable>()
3232
readonly at = new Map<string, string | number>()
3333
readonly animations = new Map<string, AnimationDefinitions>()
34-
readonly SyntaxRule = SyntaxRule
3534

3635
constructor(
3736
public customConfig?: Config
@@ -625,7 +624,7 @@ export default class MasterCSS {
625624
const syntaxRule = this.generalLayer.rules.find(({ key }) => key === ((fixedClass ? fixedClass + ' ' : '') + className))
626625
if (syntaxRule) return syntaxRule
627626
const registeredRule = this.match(className)
628-
if (registeredRule) return new this.SyntaxRule(className, this, registeredRule, fixedClass, mode)
627+
if (registeredRule) return new SyntaxRule(className, this, registeredRule, fixedClass, mode)
629628
}
630629

631630
/**

packages/core/src/rule.ts

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ export interface RuleNode {
1919
native?: CSSRule
2020
suffixSelectors?: string[]
2121
prefixSelectors?: string[]
22-
unsupported?: boolean
2322
}

packages/core/src/syntax-rule.ts

-7
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,7 @@ export class SyntaxRule extends Rule {
316316
const propertiesText: string[] = []
317317
for (const propertyName in this.declarations) {
318318
const propertyValue = this.declarations[propertyName as keyof PropertiesHyphen] as any
319-
// if (this.css.Native && VENDOR_PREFIX_REGEX.test(propertyName) && !this.css.Native.supports(propertyName, propertyValue)) {
320-
// continue
321-
// }
322319
const propertyText = propertyName + ':' + String(propertyValue)
323-
// animations
324320
if (
325321
animations
326322
&& (propertyText.startsWith('animation') || propertyText.startsWith('animation-name'))
@@ -400,9 +396,6 @@ export class SyntaxRule extends Rule {
400396
text: cssText,
401397
selectorText
402398
}
403-
if (this.css.Native && (prefixSelectorVendor || eachSuffixSelectorVendor)) {
404-
node.unsupported = !this.css.Native.supports(`selector(${selectorText})`)
405-
}
406399
if (prefixSelectors) node.prefixSelectors = prefixSelectors
407400
if (suffixSelectors) node.suffixSelectors = suffixSelectors
408401
this.nodes.push(node)

packages/runtime/e2e/progressive/selectors/index.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ test('selectors', async ({ page, browserName }) => {
3131
expect(await page.evaluate(() => cssRuntime.generalLayer.rules.find((rule) => rule.name === 'hidden::slider-thumb'))).toMatchObject({
3232
nodes: [
3333
{
34-
text: '.hidden\\:\\:slider-thumb::-webkit-slider-thumb{display:none}',
35-
unsupported: true
34+
text: '.hidden\\:\\:slider-thumb::-webkit-slider-thumb{display:none}'
3635
},
3736
{
3837
text: '.hidden\\:\\:slider-thumb::-moz-range-thumb{display:none}',

packages/runtime/src/core.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import registerGlobal from './register-global'
44
import { HydrateResult } from './types'
55
import RuntimeLayer from './layer'
66
import RuntimeSyntaxLayer, { RuntimeSyntaxLayerInstance } from './syntax-layer'
7-
import RuntimeSyntaxRule from './syntax-rule'
87

98
export default class CSSRuntime extends MasterCSS {
109
static instances = new WeakMap<Document | ShadowRoot, CSSRuntime>()
@@ -18,9 +17,7 @@ export default class CSSRuntime extends MasterCSS {
1817
readonly presetLayer = new RuntimeSyntaxLayer('preset', this)
1918
readonly componentsLayer = new RuntimeSyntaxLayer('components', this)
2019
readonly generalLayer = new RuntimeSyntaxLayer('general', this)
21-
readonly SyntaxRule = RuntimeSyntaxRule
2220
readonly classCounts = new Map<string, number>()
23-
readonly Native = CSS
2421

2522
constructor(
2623
public root: Document | ShadowRoot = document,
@@ -310,7 +307,6 @@ export default class CSSRuntime extends MasterCSS {
310307
layer.insertAnimations(createdRule)
311308
result.allSyntaxRules.push(createdRule)
312309
createdRule.nodes.forEach((node) => {
313-
if (node.unsupported) return
314310
try {
315311
const checkRuleIndex = checkSheet.insertRule(node.text)
316312
const checkNodeNativeRule = checkSheet.cssRules.item(checkRuleIndex)
@@ -323,8 +319,12 @@ export default class CSSRuntime extends MasterCSS {
323319
return
324320
}
325321
}
326-
} catch (error) { }
327-
console.error(`Cannot retrieve CSS rule for \`${node.text}\`. (${layer.name}) (https://rc.css.master.co/messages/hydration-errors)`)
322+
console.error(`Cannot retrieve CSS rule for \`${node.text}\`. (${layer.name}) (https://rc.css.master.co/messages/hydration-errors)`)
323+
} catch (error) {
324+
if (process.env.NODE_ENV === 'development') {
325+
console.debug(`Cannot insert CSS rule for \`${node.text}\`. (${layer.name}) (https://rc.css.master.co/messages/hydration-errors)`)
326+
}
327+
}
328328
})
329329
}
330330
} else {

packages/runtime/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export { default as CSSRuntime, default } from './core'
22
export { default as initCSSRuntime } from './init'
3-
export { default as RuntimeSyntaxRule } from './syntax-rule'
43
export { default as RuntimeSyntaxLayer } from './syntax-layer'
54

65
export type * from './types'

packages/runtime/src/layer.ts

+7-11
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,14 @@ export default class RuntimeLayer extends Layer {
5050

5151
for (let i = 0; i < rule.nodes.length;) {
5252
const node = rule.nodes[i]
53-
if (node.unsupported) {
53+
try {
54+
const insertedIndex = this.native.insertRule(node.text, cssRuleIndex)
55+
node.native = this.native.cssRules.item(insertedIndex) as CSSRule
56+
cssRuleIndex++
5457
i++
55-
} else {
56-
try {
57-
const insertedIndex = this.native.insertRule(node.text, cssRuleIndex)
58-
node.native = this.native.cssRules.item(insertedIndex) as CSSRule
59-
cssRuleIndex++
60-
i++
61-
} catch (error) {
62-
console.error(error, node)
63-
rule.nodes.splice(i, 1)
64-
}
58+
} catch (error) {
59+
console.error(error, node)
60+
rule.nodes.splice(i, 1)
6561
}
6662
}
6763
}

packages/runtime/src/syntax-rule.ts

-4
This file was deleted.

0 commit comments

Comments
 (0)