Skip to content

Replace inline array defaults with module-level constants for memoization optimization#10440

Open
dannguyen24 wants to merge 11 commits into
wso2:masterfrom
dannguyen24:fix-issue-27956
Open

Replace inline array defaults with module-level constants for memoization optimization#10440
dannguyen24 wants to merge 11 commits into
wso2:masterfrom
dannguyen24:fix-issue-27956

Conversation

@dannguyen24

Copy link
Copy Markdown

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:

  • features/admin.rules.v1/components/rule-conditions.tsx
  • features/admin.approval-workflows.v1/components/rules/workflow-condition-value-input.tsx
  • features/admin.approval-workflows.v1/components/rules/workflow-resource-autocomplete.tsx
  • features/admin.approval-workflows.v1/components/rules/workflow-resource-list-select.tsx
  • features/admin.flow-builder-core.v1/components/visual-flow/decorated-visual-flow.tsx
  • features/admin.policy-administration.v1/components/policy-list.tsx
  • features/admin.webhooks.v1/components/webhook-channel-config-form.tss

Related PRs

  • N/A

Checklist

  • Manual test round performed and verified.

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.

@CLAassistant

CLAassistant commented Jun 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Across six components in multiple feature modules, inline empty array literals ([]) used as default prop values are replaced with shared module-level typed constants (EMPTY_STRING_ARRAY, EMPTY_NODES, EMPTY_EDGES, EMPTY_POLICIES, EMPTY_CHANNEL_SUBSCRIPTIONS). No rendering logic, prop contracts, or behavior is changed.

Changes

Stable empty array default props

Layer / File(s) Summary
Shared empty array constants and prop defaults
features/admin.approval-workflows.v1/components/rules/workflow-condition-value-input.tsx, features/admin.approval-workflows.v1/components/rules/workflow-resource-autocomplete.tsx, features/admin.approval-workflows.v1/components/rules/workflow-resource-list-select.tsx, features/admin.flow-builder-core.v1/components/visual-flow/decorated-visual-flow.tsx, features/admin.policy-administration.v1/components/policy-list.tsx, features/admin.rules.v1/components/rule-conditions.tsx, features/admin.webhooks.v1/components/webhook-channel-config-form.tsx
Each file defines a typed module-level empty array constant and substitutes it for inline [] literals in prop destructuring defaults for hiddenResources, hiddenValues, hiddenConditions, initialNodes, initialEdges, policies, and channelSubscriptions.

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Changeset Required ❌ Error No changeset file in the PR's changed files list. The PR modifies 7 feature files (non-exempt) but does not include a new .changeset/*.md file in its changes. Add a new .changeset/*.md file documenting all changed packages: @wso2is/admin.rules.v1, @wso2is/admin.approval-workflows.v1, @wso2is/admin.flow-builder-core.v1, @wso2is/admin.policy-administration.v1, @wso2is/admin.webhooks.v1, @wso2is/...
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description is comprehensive and includes purpose, related issues, and appropriate sections; all required information is present and well-documented.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the main change: replacing inline array defaults with module-level constants for memoization optimization, which is the core objective of the PR.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ create changeset

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dannguyen24 dannguyen24 changed the title Fix issue 27956 Fix issue 27956 - Replace inline array defaults with module-level constants for memoization optimization Jun 20, 2026
@pavinduLakshan pavinduLakshan changed the title Fix issue 27956 - Replace inline array defaults with module-level constants for memoization optimization Replace inline array defaults with module-level constants for memoization optimization Jun 21, 2026

@pavinduLakshan pavinduLakshan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
}) { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants