Skip to content

Commit

Permalink
[Cases] Fix attachment's renderer memoization (elastic#156179)
Browse files Browse the repository at this point in the history
## Summary

PR elastic#154436 changed the memoization
function (my fault 🙂) and that caused the attachments to rerender each
time a user does an action in cases. This PR fixes this issue.

**Before:**

https://user-images.githubusercontent.com/7871006/235171360-62be773f-8317-4762-9f14-0310d3825a1e.mov

**After:**

https://user-images.githubusercontent.com/7871006/235171429-5e06f9c4-9c0a-4148-8580-bde2360169af.mov

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 60e3d98)
  • Loading branch information
cnasikas committed Apr 28, 2023
1 parent e2c108c commit 3b17402
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ type BuilderArgs<C, R> = Pick<
/**
* Provides a render function for attachment type
*/
const getAttachmentRenderer = memoize((attachmentViewObject: AttachmentViewObject) => {
const getAttachmentRenderer = memoize(() => {
let AttachmentElement: React.ReactElement;

const renderCallback = (props: object) => {
const renderCallback = (attachmentViewObject: AttachmentViewObject, props: object) => {
if (!attachmentViewObject.children) return;

if (!AttachmentElement) {
Expand Down Expand Up @@ -120,7 +120,7 @@ export const createRegisteredAttachmentUserActionBuilder = <

const attachmentViewObject = attachmentType.getAttachmentViewObject(props);

const renderer = getAttachmentRenderer(attachmentViewObject);
const renderer = getAttachmentRenderer();
const actions = attachmentViewObject.getActions?.(props) ?? [];
const [primaryActions, nonPrimaryActions] = partition(actions, 'isPrimary');
const visiblePrimaryActions = primaryActions.slice(0, 2);
Expand Down Expand Up @@ -164,7 +164,7 @@ export const createRegisteredAttachmentUserActionBuilder = <
/>
</UserActionContentToolbar>
),
children: renderer(props),
children: renderer(attachmentViewObject, props),
},
];
},
Expand Down

0 comments on commit 3b17402

Please sign in to comment.