-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix(runtime): generated <comp /> cannot use style #18877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rdjanuar
wants to merge
2
commits into
NervJS:main
Choose a base branch
from
rdjanuar:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
examples/mini-program-example/src/pages/style-isolation/index.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| .red-text { | ||
| color: red; | ||
| font-size: 40px; | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| .container { | ||
| padding: 20px; | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
examples/mini-program-example/src/pages/style-isolation/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { Component } from 'react' | ||
| import { View, Text } from '@tarojs/components' | ||
| import './index.scss' | ||
|
|
||
| export default class Index extends Component { | ||
| render () { | ||
| return ( | ||
| <View className='container'> | ||
| <View>Level 1</View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <View> | ||
| <Text className='red-text'>Level 21 - Should be RED</Text> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| </View> | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { afterEach, describe, expect, test } from 'vitest' | ||
|
|
||
| import { createRecursiveComponentConfig } from '../../src/dsl/common' | ||
|
|
||
| describe('createRecursiveComponentConfig', () => { | ||
| const originalEnv = process.env.TARO_ENV | ||
|
|
||
| afterEach(() => { | ||
| process.env.TARO_ENV = originalEnv | ||
| }) | ||
|
|
||
| test('should set styleIsolation to apply-shared for harmony-hybrid', () => { | ||
| process.env.TARO_ENV = 'harmony-hybrid' | ||
| const config = createRecursiveComponentConfig() | ||
| expect(config.options?.styleIsolation).toBe('apply-shared') | ||
| }) | ||
|
|
||
| test('should set styleIsolation to apply-shared for weapp', () => { | ||
| process.env.TARO_ENV = 'weapp' | ||
| const config = createRecursiveComponentConfig() | ||
| expect(config.options?.styleIsolation).toBe('apply-shared') | ||
| }) | ||
|
|
||
| test('should not set styleIsolation for other environments (e.g. h5)', () => { | ||
| process.env.TARO_ENV = 'h5' | ||
| const config = createRecursiveComponentConfig() | ||
| expect(config.options?.styleIsolation).toBeUndefined() | ||
| }) | ||
|
|
||
| test('should set addGlobalClass for jd', () => { | ||
| process.env.TARO_ENV = 'jd' | ||
| const config = createRecursiveComponentConfig() | ||
| expect(config.options?.addGlobalClass).toBe(true) | ||
| expect(config.options?.styleIsolation).toBeUndefined() | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
px单位与截图不一致,建议改为rpx截图中开发者工具显示的是
font-size: 40rpx,而代码中为40px。对于微信小程序,rpx是推荐的响应式单位。🛠️ 建议修改
📝 Committable suggestion
🤖 Prompt for AI Agents