fix/3714 hide api#3720
Conversation
📝 WalkthroughWalkthroughAdds a ChangesSensitive value masking
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant AdminTextSetting
participant maskSensitiveValue
User->>AdminTextSetting: click input
AdminTextSetting->>AdminTextSetting: focus and select (if maskValue)
User->>AdminTextSetting: focus event
AdminTextSetting->>AdminTextSetting: set isEditing = true
User->>AdminTextSetting: types new value
AdminTextSetting->>AdminTextSetting: onChange allowed (isEditing)
User->>AdminTextSetting: blur event
AdminTextSetting->>AdminTextSetting: set isEditing = false
AdminTextSetting->>maskSensitiveValue: mask value for display
maskSensitiveValue-->>AdminTextSetting: masked string
Related Issues
Suggested labels: enhancement, security Suggested reviewers: gambitph Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 Pull request artifacts
|
|
Size Change: +373 B (+0.01%) Total Size: 2.63 MB 📦 View Changed
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/admin-text-setting/index.js`:
- Line 2: The ref used in admin-text-setting is being recreated on every render
because it imports and uses createRef alongside useState, which can break the
delayed select behavior after setIsEditing(true). Update the component to use
useRef instead of createRef so the same ref instance is preserved across
renders, and keep the auto-select logic in the existing timeout callback working
through ref.current?.select().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 32bbbd4c-c46b-479f-9961-30b85a33d847
📒 Files selected for processing (3)
src/components/admin-text-setting/index.jssrc/util/index.jssrc/welcome/admin.js
| @@ -1,23 +1,43 @@ | |||
| import AdminBaseSetting from '../admin-base-setting' | |||
| import { createRef } from '@wordpress/element' | |||
| import { createRef, useState } from '@wordpress/element' | |||
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Does @wordpress/element export a useRef hook mirroring React's API?
💡 Result:
Yes, the @wordpress/element package exports a useRef hook that mirrors the React API [1][2][3]. This package serves as an abstraction layer over React, allowing developers to use familiar React hooks and utilities within the WordPress environment [4]. You can import and use it in the same manner as you would in a standard React application [3].
Citations:
- 1: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-element/?output_format=md
- 2: https://github.com/WordPress/gutenberg/blob/trunk/packages/element/README.md
- 3: ref="ref" breaks toolbar WordPress/gutenberg#68302
- 4: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-element/
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## File list\n'
git ls-files src/components/admin-text-setting
printf '\n## Outline\n'
ast-grep outline src/components/admin-text-setting/index.js --view expanded || true
printf '\n## File content with line numbers\n'
cat -n src/components/admin-text-setting/index.js
printf '\n## Search for ref usage in the component\n'
rg -n "createRef|useRef|ref\.current|select\(" src/components/admin-text-setting/index.jsRepository: gambitph/Stackable
Length of output: 2423
Replace createRef() with useRef() here.
createRef() is recreated on every render, so the setIsEditing(true) re-render leaves the timeout callback holding a detached ref and ref.current?.select() can no-op. useRef() keeps the same ref instance across renders and preserves the auto-select behavior.
🔧 Proposed fix
-import { createRef, useState } from '`@wordpress/element`'
+import { useRef, useState } from '`@wordpress/element`'
import { maskSensitiveValue } from '~stackable/util'
const AdminTextSetting = props => {
- const ref = createRef()
+ const ref = useRef()
const [ isEditing, setIsEditing ] = useState( false )📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { createRef, useState } from '@wordpress/element' | |
| import { useRef, useState } from '`@wordpress/element`' | |
| import { maskSensitiveValue } from '~stackable/util' | |
| const AdminTextSetting = props => { | |
| const ref = useRef() | |
| const [ isEditing, setIsEditing ] = useState( false ) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/admin-text-setting/index.js` at line 2, The ref used in
admin-text-setting is being recreated on every render because it imports and
uses createRef alongside useState, which can break the delayed select behavior
after setIsEditing(true). Update the component to use useRef instead of
createRef so the same ref instance is preserved across renders, and keep the
auto-select logic in the existing timeout callback working through
ref.current?.select().
fixes #3714
Summary by CodeRabbit
New Features
Bug Fixes