fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

I am unable to register and icon alias after an icon is mounted

Open jacksonv1lle opened this issue 6 years ago • 5 comments

Environment Information

  • Package version(s): current

Please provide a reproduction of the bug in a codepen:

https://codepen.io/ijackson/pen/bGVpGow?editors=0010

Describe the issue

I am trying to implement a way to dynamically swap between the default Fabric/Fluent icons set and a set of custom SVG icons. For this to work I want to use the registerIconAlias function to apply the custom icons upon clicking a button.

In the pen above, I have set up a simple scenario. I want to replace the 'Delete' icon with the custom 'svg-circle'. This works when I place the registerIconAlias block before the class definition. But I would like for this to work dynamically.

Actual behavior:

Upon clicking the button, the 'Delete' icon remains the same

Expected behavior:

Upon clicking the button, the 'Delete' icon is expected to change to the circle shape having used the registerIconAlias function inside the click handler function.

Priorities and help requested:

Are you willing to submit a PR to fix? No

Requested priority: Normal

jacksonv1lle avatar Apr 16 '20 14:04 jacksonv1lle

@jacksonv1lle Thanks for the submission! This is an interesting case. The "Delete Icon" won't actually change, even if you render an entirely new icon. I modified your codpen here and you can see that behavior.

I'm fairly certain this is happening because of this line in font icon. The function that retrieves the Icon content is memoized to help increase its overall speed. The problem that you're encountering is that the memoization doesn't know about the icons at large, it only knows about the string that's coming in so it will return same the value for the same string even if the global value may have changed.

So there is a workaround, you can call resetMemoizations but that should be handled carefully since it can heavily impact perf. Here's another modified version of your codepen with things working as you'd expect. You also will need to change something going to the icon, as force update only triggers children to go through their standard react life cycle, which means they won't update if they don't receive new props.

@ecraig12345 might have something else to add about this.

joschect avatar Apr 18 '20 00:04 joschect

Hi @joschect. Thanks for your reply. I see now how the icon references are memoized. I didn't know about the resetMemoizations function. This is very helpful.

I have also noticed this line in the FontIcon file stating that the FontIcon can't be targeted by customizations. Is there an Icon component which can be targeted by customizations?

jacksonv1lle avatar Apr 20 '20 10:04 jacksonv1lle

@jacksonv1lle Sorry for my slow response. I believe that is only for the FastIcons, regular icons can be targeted by customizations. I believe in your codepen you're using the Icon component which is customizable. That's the tradeoff of using the FontIcon in isolation.

joschect avatar May 01 '20 18:05 joschect

This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fabric React!

msft-github-bot avatar May 05 '20 20:05 msft-github-bot

This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fluent UI!

msft-github-bot avatar May 09 '20 23:05 msft-github-bot