Skip to content

Conversation

@reneshen0328
Copy link
Contributor

@reneshen0328 reneshen0328 commented Jan 8, 2026

What

  • Memoize the config object to avoid unnecessary renders
  • Pass in config in the root content sharing level and pass into USM shared feature config prop for consumer to override default props.

Summary by CodeRabbit

  • New Features

    • Content sharing now accepts a broader external configuration object and merges it with safe defaults, enabling additional customization (e.g., collaboration limits) and allowing consumers to override defaults (such as shared-link behavior).
    • Consumers can enable additional UI controls (e.g., "Send Shared Link") via config.
  • Tests

    • Added tests verifying custom config enables modal features and can override defaults.

✏️ Tip: You can customize this high-level summary in your review settings.

@reneshen0328 reneshen0328 requested review from a team as code owners January 8, 2026 15:18
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 8, 2026

Walkthrough

Widened the public config prop to accept Configuration from @box/unified-share-modal, threaded config from ContentSharing into ContentSharingV2, memoized a merged config ({ sharedLinkEmail: false, ...usmConfig }), and added tests validating custom-config behavior.

Changes

Cohort / File(s) Summary
Config prop support
src/elements/content-sharing/ContentSharing.js, src/elements/content-sharing/ContentSharingV2.tsx
Widened config prop type to USMConfig | Configuration, pass config from ContentSharingContentSharingV2, and accept config in V2's props.
Config merging logic
src/elements/content-sharing/ContentSharingV2.tsx
Added config?: Configuration prop; destructures config: usmConfig = {} and memoizes merged config ({ sharedLinkEmail: false, ...usmConfig }).
Imports & typing
src/elements/content-sharing/...
Imported type Configuration from @box/unified-share-modal; reorganized import order and Flow/TS types (FeatureConfig, constants).
Tests
src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx
Added tests asserting UnifiedShareModal renders with provided custom config and that custom config overrides defaults (e.g., sharedLinkEmail).

Sequence Diagram(s)

sequenceDiagram
    participant Consumer
    participant ContentSharing
    participant ContentSharingV2
    participant UnifiedShareModal

    Consumer->>ContentSharing: render(api, config, itemID, itemType, ...)
    ContentSharing->>ContentSharingV2: render(api, config, itemId, itemType, children)
    ContentSharingV2->>ContentSharingV2: memoize mergedConfig = { sharedLinkEmail: false, ...usmConfig }
    ContentSharingV2->>UnifiedShareModal: render with mergedConfig and props
    UnifiedShareModal-->>Consumer: modal UI reflects mergedConfig
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • tjuanitas
  • jfox-box

Poem

🐇 I stitched a config with careful paws,
Defaults tucked in without a pause.
Merged and memoized, neat as a seam,
The modal wakes up, ready to beam.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main changes: memoizing config for performance and enabling consumer config override.
Description check ✅ Passed The PR description addresses the main objectives but lacks detailed context about implementation details or testing approach.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

@reneshen0328 reneshen0328 changed the title fix(content-sharing): Improve content sharing performance fix(content-sharing): Improve content sharing performance and add consumer ability to override config Jan 8, 2026
@reneshen0328 reneshen0328 force-pushed the fix-improve-content-sharing branch from 3a74221 to 97b1e57 Compare January 8, 2026 15:31
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @src/elements/content-sharing/ContentSharingV2.tsx:
- Line 36: The default parameter in ContentSharingV2 (config: usmConfig = {})
creates a fresh object each render and breaks memoization; define a stable empty
object constant (e.g., STABLE_EMPTY_CONFIG) outside the component and change the
component to use that stable reference when no config is passed (either via
default param pointing to that constant or by assigning inside the function),
then ensure the useMemo that relies on usmConfig uses this stable reference so
it no longer recomputes every render.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 254f89d and 3a74221.

📒 Files selected for processing (2)
  • src/elements/content-sharing/ContentSharing.js
  • src/elements/content-sharing/ContentSharingV2.tsx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-11T14:43:02.677Z
Learnt from: jpan-box
Repo: box/box-ui-elements PR: 4166
File: src/elements/content-sidebar/SidebarNav.js:126-126
Timestamp: 2025-07-11T14:43:02.677Z
Learning: In the box-ui-elements repository, there's a file-type-based pattern for internationalization: TypeScript files (.tsx) predominantly use the modern useIntl hook (41 vs 15 files), while JavaScript files (.js) predominantly use the legacy injectIntl HOC (64 vs 5 files). New TypeScript components should use useIntl, while existing JavaScript components typically continue using injectIntl for consistency.

Applied to files:

  • src/elements/content-sharing/ContentSharingV2.tsx
🪛 Biome (2.1.2)
src/elements/content-sharing/ContentSharing.js

[error] 12-12: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 24-24: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 25-25: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 26-26: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: lint_test_build
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Summary
🔇 Additional comments (6)
src/elements/content-sharing/ContentSharing.js (3)

12-12: LGTM! Type imports are correctly structured.

The addition of the Configuration type import from @box/unified-share-modal properly supports the widened config prop type. The static analysis warnings about import type being TypeScript-only are false positives—this is valid Flow syntax in a Flow-annotated file.

Also applies to: 24-28


40-40: LGTM! Backward-compatible type widening.

The config prop type now accepts both USMConfig and Configuration, allowing consumers to use either type while maintaining backward compatibility.


128-128: LGTM! Config prop correctly threaded through.

The config prop is now properly passed to ContentSharingV2, enabling configuration customization as intended by the PR objectives.

src/elements/content-sharing/ContentSharingV2.tsx (3)

7-7: LGTM! Type imports properly support the new config prop.

The addition of Configuration and USMConfig type imports correctly enables type-safe config handling.

Also applies to: 18-18


28-29: LGTM! Prop definition matches parent component.

The config prop definition correctly uses the union type USMConfig | Configuration, maintaining type consistency with ContentSharing.js.


214-214: LGTM! Config merging logic is correct.

The memoization correctly merges the default sharedLinkEmail: false with the provided config, allowing consumers to override defaults. The dependency array [usmConfig] is appropriate. (Note: This will work optimally once the default parameter issue on line 36 is addressed.)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx:
- Around line 180-190: The test "should allow custom config to override default
config" incorrectly sets config.sharedLinkEmail; update it to set the correct
property used by the component: pass config: { showEmailSharedLinkForm: true }
when calling renderComponent so the "Send Shared Link" button visibility is
controlled by showEmailSharedLinkForm; locate the test in
ContentSharingV2.test.tsx and change the config object in the renderComponent
call accordingly (the test uses apiWithSharedLink, getFileMockWithSharedLink,
and renderComponent).
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a74221 and 97b1e57.

📒 Files selected for processing (3)
  • src/elements/content-sharing/ContentSharing.js
  • src/elements/content-sharing/ContentSharingV2.tsx
  • src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/elements/content-sharing/ContentSharingV2.tsx
🧰 Additional context used
🪛 Biome (2.1.2)
src/elements/content-sharing/ContentSharing.js

[error] 12-12: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 24-24: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 25-25: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 26-26: 'import type' are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint_test_build
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Summary
🔇 Additional comments (5)
src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx (1)

173-178: LGTM! Good coverage for custom config rendering.

The test correctly verifies that UnifiedShareModal renders when a custom config is provided.

src/elements/content-sharing/ContentSharing.js (4)

12-12: LGTM! Configuration type import added correctly.

This enables the widened config prop type to support both USMConfig and Configuration from the unified-share-modal library.


40-40: LGTM! Config prop type appropriately widened.

The expanded type USMConfig | Configuration allows consumers to provide either configuration format, which aligns with the PR objectives.


128-128: LGTM! Config properly threaded to ContentSharingV2.

The config prop is now correctly passed through to the ContentSharingV2 component.


12-12: Static analysis errors are false positives.

Biome is flagging import type as "TypeScript only," but this is a Flow file (note the @flow comment at line 2). Flow fully supports import type syntax—these warnings can be safely ignored.

Also applies to: 24-26

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (1)
src/elements/content-sharing/ContentSharingV2.tsx (1)

35-35: Default empty object defeats memoization when no config is provided.

The inline default config: usmConfig = {} creates a new object reference on each render. Since useMemo on line 213 depends on usmConfig, the memo recomputes every render when consumers don't pass a config — defeating the PR's goal of avoiding unnecessary renders.

Define a stable default outside the component:

♻️ Proposed fix
+const DEFAULT_USM_CONFIG: Configuration = {};
+
-function ContentSharingV2({ api, children, config: usmConfig = {}, itemId, itemType }: ContentSharingV2Props) {
+function ContentSharingV2({ api, children, config: usmConfig = DEFAULT_USM_CONFIG, itemId, itemType }: ContentSharingV2Props) {

Also applies to: 213-213

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97b1e57 and 0a4419a.

📒 Files selected for processing (1)
  • src/elements/content-sharing/ContentSharingV2.tsx
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-11T14:43:02.677Z
Learnt from: jpan-box
Repo: box/box-ui-elements PR: 4166
File: src/elements/content-sidebar/SidebarNav.js:126-126
Timestamp: 2025-07-11T14:43:02.677Z
Learning: In the box-ui-elements repository, there's a file-type-based pattern for internationalization: TypeScript files (.tsx) predominantly use the modern useIntl hook (41 vs 15 files), while JavaScript files (.js) predominantly use the legacy injectIntl HOC (64 vs 5 files). New TypeScript components should use useIntl, while existing JavaScript components typically continue using injectIntl for consistency.

Applied to files:

  • src/elements/content-sharing/ContentSharingV2.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: lint_test_build
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Summary
🔇 Additional comments (2)
src/elements/content-sharing/ContentSharingV2.tsx (2)

7-7: LGTM!

Correctly importing the Configuration type from @box/unified-share-modal alongside the component that uses it.


27-28: LGTM!

Clear documentation and proper optional typing for the new configuration prop.

@reneshen0328 reneshen0328 force-pushed the fix-improve-content-sharing branch from 0a4419a to 806abc1 Compare January 8, 2026 18:38
@reneshen0328 reneshen0328 force-pushed the fix-improve-content-sharing branch from 806abc1 to 7bbe8f3 Compare January 8, 2026 18:43
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (2)
src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx (2)

171-174: Consider strengthening this test to validate config usage.

This test verifies the component renders when config is provided, but doesn't validate that collaborationLimit: 3 actually affects behavior. Consider adding assertions that verify the config property is respected (e.g., checking that collaboration limits are enforced in the UI).


176-184: Test correctly validates config override behavior.

The test properly verifies that sharedLinkEmail: true enables the "Send Shared Link" button. For more comprehensive coverage, consider adding a complementary test that verifies the button is not visible when using the default config (without the override).

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 806abc1 and 5099113.

📒 Files selected for processing (2)
  • src/elements/content-sharing/ContentSharingV2.tsx
  • src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/elements/content-sharing/ContentSharingV2.tsx
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-02T16:47:50.715Z
Learnt from: reneshen0328
Repo: box/box-ui-elements PR: 4322
File: src/elements/content-sharing/utils/__mocks__/ContentSharingV2Mocks.js:30-36
Timestamp: 2025-10-02T16:47:50.715Z
Learning: In src/elements/content-sharing/utils/__mocks__/ContentSharingV2Mocks.js, mockCurrentUserID is intentionally a number (789) while DEFAULT_USER_API_RESPONSE.id is a string ('789'). This represents different stages of data transformation: mockCurrentUserID is the raw API response before conversion, and DEFAULT_USER_API_RESPONSE.id is the post-conversion state after fetchCurrentUser processes it.

Applied to files:

  • src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx
📚 Learning: 2025-08-27T17:03:48.322Z
Learnt from: bxie-box
Repo: box/box-ui-elements PR: 4250
File: src/features/classification/applied-by-ai-classification-reason/__tests__/AppliedByAiClassificationReason.test.tsx:44-51
Timestamp: 2025-08-27T17:03:48.322Z
Learning: In test files for bxie-box, prefer using queryByTestId over getByTestId when testing for expected elements that should always exist, as null access serves as validation for regressions or unexpected changes rather than masking issues with defensive assertions.

Applied to files:

  • src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: lint_test_build
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Summary
🔇 Additional comments (1)
src/elements/content-sharing/__tests__/ContentSharingV2.test.tsx (1)

168-169: Good improvement to async assertion pattern.

Replacing waitFor with findByRole is more idiomatic, as findByRole already waits for the element to appear.

@mergify mergify bot added the queued label Jan 8, 2026
@mergify mergify bot merged commit 788b32f into master Jan 8, 2026
12 checks passed
@mergify mergify bot deleted the fix-improve-content-sharing branch January 8, 2026 19:41
@mergify
Copy link
Contributor

mergify bot commented Jan 8, 2026

Merge Queue Status

✅ The pull request has been merged at 5099113

This pull request spent 5 seconds in the queue, with no time running CI.
The checks were run in-place.

Required conditions to merge

@mergify mergify bot removed the queued label Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants