-
Notifications
You must be signed in to change notification settings - Fork 328
fix(select): [select] fix state.selected.state is empty object, and can't get the right displayText #2902
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
Conversation
…the right displayText
WalkthroughThe changes update the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Component
participant S as State
participant CP as ComputedProps
participant A as API
participant W as Watchers
C->>S: Call initState
S->>CP: Compute properties (icon, tag type, text, size map)
CP->>A: Assign computed methods to API (including clear & closable methods)
A-->>C: Exposed API methods for external use
W->>S: Monitor gridData/treeData changes
S->>CP: Recompute properties on data update
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
packages/renderless/src/select/vue.tsOops! Something went wrong! :( ESLint: 8.57.1 ESLint couldn't find the plugin "eslint-plugin-vue". (The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".) It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue". If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team. ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Walkthrough修复了 select 组件在单选和只读状态下, Changes
|
? state.selected.state.currentLabel | ||
: state.selected.currentLabel || state.selected.label) || '' | ||
) | ||
return state.selected.state?.currentLabel || state.selected.currentLabel || state.selected.label || '' |
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.
The use of optional chaining (?.
) is a good approach here to safely access currentLabel
from state.selected.state
. This change ensures that if state.selected.state
is undefined, it won't cause an error, and the code will continue to check state.selected.currentLabel
and state.selected.label
. This effectively fixes the issue where state.selected.state
could be an empty object.
WalkthroughFixed an issue where the Changes
|
[e2e-test-warn] The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug". Please make sure you've read our contributing guide |
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.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
packages/renderless/src/select/vue.ts (2)
434-440
: 🛠️ Refactor suggestionConsider adding error handling for edge cases.
The new API methods should include error handling for edge cases, especially for
clearNoMatchValue
which interacts with props and emit.- clearNoMatchValue: clearNoMatchValue({ props, emit }), + clearNoMatchValue: clearNoMatchValue({ props, emit, state }) { + try { + if (props.multiple) { + emit('update:modelValue', []) + } else { + emit('update:modelValue', '') + } + state.query = '' + } catch (error) { + console.error('Failed to clear no-match value:', error) + } + },
595-601
: 💡 Verification agent🧩 Analysis chain
Verify the immediate flag for grid and tree data watchers.
The watchers for
gridData
andtreeData
might need theimmediate
flag to handle initial values correctly, similar to other watchers in the file.if (props.renderType === 'grid' && !props.optimization) { - watch(() => state.gridData, api.setSelected, { immediate: true }) + watch(() => state.gridData, api.setSelected, { immediate: true, deep: true }) } if (props.renderType === 'tree' && !props.optimization) { - watch(() => state.treeData, api.setSelected, { immediate: true }) + watch(() => state.treeData, api.setSelected, { immediate: true, deep: true }) }Let's verify if the watchers need deep observation:
🏁 Script executed:
#!/bin/bash # Search for nested data structures in gridData and treeData ast-grep --pattern 'state.gridData = $_' -l typescript ast-grep --pattern 'state.treeData = $_' -l typescriptLength of output: 777
Action Required: Update Watchers to Include Deep Observation
The verification confirms that both
gridData
andtreeData
are assigned nested data structures in various parts of the codebase. To ensure that changes in nested properties trigger the watchers, please update the watchers inpackages/renderless/src/select/vue.ts
to include thedeep: true
flag:
- Location:
packages/renderless/src/select/vue.ts
(Lines 595-601)- Change: Update the watchers so that they use
{ immediate: true, deep: true }
, as shown in the diff snippet below.if (props.renderType === 'grid' && !props.optimization) { - watch(() => state.gridData, api.setSelected, { immediate: true }) + watch(() => state.gridData, api.setSelected, { immediate: true, deep: true }) } if (props.renderType === 'tree' && !props.optimization) { - watch(() => state.treeData, api.setSelected, { immediate: true }) + watch(() => state.treeData, api.setSelected, { immediate: true, deep: true }) }The
ast-grep
results confirm that these state properties are updated in multiple files (e.g., assignments inindex.ts
and other related components), supporting the addition of deep observation to track nested changes.
🧹 Nitpick comments (1)
packages/renderless/src/select/vue.ts (1)
266-276
: Consider memoizing computed properties for better performance.The new computed properties (
getIcon
,getTagType
,isSelectAll
,currentSizeMap
) might benefit from memoization to prevent unnecessary recalculations, especially in components that re-render frequently.- getIcon: computed(() => api.computedGetIcon()), + getIcon: computed(() => { + const result = api.computedGetIcon() + return () => result + }),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/renderless/src/select/vue.ts
(1 hunks)
🔇 Additional comments (1)
packages/renderless/src/select/vue.ts (1)
254-254
: LGTM! Improved robustness with optional chaining.The addition of optional chaining operator (
?.
) for accessingcurrentLabel
makes the code more resilient to undefined states.
…the right displayText
PR
修复 select 组件单选,只读时, state.selected.state对象是空的object, 造成无法取到正确的label值
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit