Skip to content

Commit 7556bb1

Browse files
authored
Merge pull request #1694 from jd-opensource/feature_micro
Feature micro
2 parents 0c67209 + ee8c619 commit 7556bb1

9 files changed

Lines changed: 56 additions & 3 deletions

File tree

dev/children/react17/src/App.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
:root {
3+
/* 主题色 */
4+
--text-color: blue;
5+
}
6+
17
.App {
28
text-align: center;
39
}
@@ -23,6 +29,9 @@
2329
color: #333;
2430
/* test about @container */
2531
container-type: inline-size;
32+
p {
33+
color: var(--text-color);
34+
}
2635
}
2736

2837
@container (max-width: 1000px) {

dev/main-react16/src/components/HeaderSearch/index.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@import '~antd/es/style/themes/default.less';
22

33
.headerSearch {
4+
.anticon{
5+
color: var(--text-color);
6+
}
47
.input {
58
width: 0;
69
min-width: 0;

dev/main-react16/src/global.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ microApp.start({
9393
// return node.parentElement
9494
// },
9595
// iframeSrc: 'http://localhost:3000/',
96+
optionCss: ['isolation-root'],//有isolation-root(子应用:root 中定义的变量不起作用,默认用基座的)
9697
lifeCycles: {
9798
created (e, appName) {
9899
console.log(`子应用${appName}被创建 -- 全局监听`)

dev/main-react16/src/pages/react17/react17.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import microApp from '@micro-zoe/micro-app'
66
import { Spin } from 'antd'
77
import { LoadingOutlined } from '@ant-design/icons'
88
import config from '../../config'
9+
import './react17.less'
910

1011
const antIcon = <LoadingOutlined style={{ fontSize: 30 }} spin />
1112

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
:root {
3+
/* 主题色 */
4+
--text-color: red; //基座
5+
}
6+
7+
#logo.ant-pro-sider-logo h1{
8+
color:var(--text-color);
9+
}

docs/zh-cn/advanced.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,14 @@ microApp.start({
110110
// iframe模式下,不对事件对象的原型判断进行代理
111111
excludeRewriteIframeConstructor: ['EventTarget']
112112
})
113+
```
114+
115+
## 8、optionCss : css属性隔离配置项
116+
```js
117+
import microApp from '@micro-zoe/micro-app'
118+
119+
microApp.start({
120+
// 有isolation-root(子应用:root 中定义的变量失效,默认用基座的)
121+
optionCss: ['isolation-root']
122+
})
113123
```

docs/zh-cn/changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77
- 修订版本号:每周末会进行日常 bugfix 更新。(如果有紧急的 bugfix,则任何时候都可发布)
88

99
---
10-
### 1.0.0-rc.30
10+
### 1.0.0-rc.31
11+
12+
`2026-06-09`
13+
- **Feature**
14+
- 新增Css隔离选项:支持子应用:root 中定义的变量失效,用基座的。可设置成optionCss: ['isolation-root']
1115

16+
### 1.0.0-rc.30
1217
`2026-04-20`
1318
- **Bug Fix**
1419
- 🐞 修复 Int16Array(),Int32Array(),Int8Array(),Float16Array()方法不支持,[issue 1589](https://github.com/jd-opensource/micro-app/issues/1589)
1520
- 🐞 修复 子应用使用 tailwindcss 4 无法正常工作,[issue 1550](https://github.com/jd-opensource/micro-app/issues/1550)
21+
1622
### 1.0.0-rc.29
1723

1824
`2026-01-30`

src/sandbox/scoped_css.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { AppInterface } from '@micro-app/types'
33
import { CompletionPath, getLinkFileDir, logError, trim, isFireFox } from '../libs/utils'
44
import microApp from '../micro_app'
55

6-
// common reg
7-
const rootSelectorREG = /(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/
6+
// common regular expression
7+
// const rootSelectorREG = /(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/
88
const bodySelectorREG = /(^|\s+)((html[\s>~]+body)|body)(?=[\s>~[.#:]+|$)/
99

1010
type parseErrorType = Error & { reason: string, filename?: string }
@@ -34,6 +34,7 @@ class CSSParser {
3434
private scopecssDisable = false // use block comments /* scopecss-disable */ to disable scopecss in your file, and use /* scopecss-enable */ to enable scopecss
3535
private scopecssDisableSelectors: Array<string> = [] // disable or enable scopecss for specific selectors
3636
private scopecssDisableNextLine = false // use block comments /* scopecss-disable-next-line */ to disable scopecss on a specific line
37+
private optionCssSelectors: Array<string> = [] // use this option to include specific selectors, so that they will be affected by scopecss ,like microApp.options.optionCss
3738

3839
public exec (
3940
cssText: string,
@@ -45,6 +46,8 @@ class CSSParser {
4546
this.prefix = prefix
4647
this.baseURI = baseURI
4748
this.linkPath = linkPath || ''
49+
// fetch optionCss configure
50+
this.optionCssSelectors = microApp.options.optionCss || []
4851

4952
this.matchRules()
5053
return isFireFox() ? decodeURIComponent(this.result) : this.result
@@ -54,6 +57,7 @@ class CSSParser {
5457
this.cssText = this.prefix = this.baseURI = this.linkPath = this.result = ''
5558
this.scopecssDisable = this.scopecssDisableNextLine = false
5659
this.scopecssDisableSelectors = []
60+
this.optionCssSelectors = []
5761
}
5862

5963
// core action for match rules
@@ -123,6 +127,15 @@ class CSSParser {
123127
}
124128
return match
125129
})
130+
131+
// Check if it is in the optionCss list
132+
const isIsolationRoot = this.optionCssSelectors.some(includeSelector => {
133+
// isolation-root is used to isolation the :root styles between base-app and sub-app
134+
if (includeSelector === 'isolation-root') return true
135+
return false
136+
})
137+
const rootSelectorREG = isIsolationRoot ? /(^|\s+)(html)(?=[\s>~[.#:]+|$)/ : /(^|\s+)(html|:root)(?=[\s>~[.#:]+|$)/ // without root
138+
126139
if (selector && !(
127140
this.scopecssDisableNextLine ||
128141
(

typings/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ declare module '@micro-app/types' {
373373
escapeIframeWindowEvents? : Array<string>,
374374
disableIframeRootDocument?: boolean,
375375
excludeRewriteIframeConstructor?: string[]
376+
optionCss?: string[] // some configurations of CSS
376377
}
377378

378379
// MicroApp config

0 commit comments

Comments
 (0)