Replace inline array defaults with module-level constants for memoization optimization#10440
Replace inline array defaults with module-level constants for memoization optimization#10440dannguyen24 wants to merge 11 commits into
Conversation
📝 WalkthroughWalkthroughAcross six components in multiple feature modules, inline empty array literals ( ChangesStable empty array default props
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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 |
pavinduLakshan
left a comment
There was a problem hiding this comment.
Hi @dannguyen24,
The per-type naming in decorated-visual-flow.tsx (EMPTY_NODES, EMPTY_EDGES) is actually good as it communicates intent clearly. But EMPTY_STRING_ARRAY repeated in many files, which looks like duplication.
A reasonable middle ground would be to define EMPTY_ARRAY in @wso2is/core for the generic string[] cases, and keep named typed constants only where the type is non-obvious (e.g. EMPTY_NODES/EMPTY_EDGES).
Eg:
// in modules/core
export const EMPTY_ARRAY: never[] = Object.freeze([]) as unknown as never[];
// in components
import { EMPTY_ARRAY } from "@wso2is/core/constants";
function MyComponent({
hiddenResources = EMPTY_ARRAY,
policies = EMPTY_ARRAY,
initialNodes = EMPTY_ARRAY,
}) { ... }
Purpose
Fix inline array default prop references that create new array objects on every render, defeating memoization. Replaces 20 occurrences of inline
= []prop defaults with module-level constants typed to the correct array type across 7 files in 5 feature packages.Issue: wso2/product-is#27956
Files modified:
Related PRs
Checklist
Security checks
Developer Checklist (Mandatory)
[Behavioural Change] No, this is a pure performance refactor. Component output and behavior are identical. Only the memory reference of default array props changed, which is invisible to users.
[Migration Impact] No, no API changes, no data changes, no breaking changes.
[New Configuration] No, no new props, config keys, or deployment configuration changes.