Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FunctionComponent.Of functions cache breaks reusable code #241

Open
DunetsNM opened this issue May 16, 2024 · 1 comment
Open

FunctionComponent.Of functions cache breaks reusable code #241

DunetsNM opened this issue May 16, 2024 · 1 comment

Comments

@DunetsNM
Copy link
Contributor

This is how FunctionComponent.Of caches passed function:

// Cache the render function to prevent recreating the component every time when FunctionComponent.Of
// is called inside another function (including generic values: let MyCom<'T> = ...)
let cacheKey = __callingSourceFile.Value + "#L" + (string __callingSourceLine.Value)

I have a reusable piece of code that uses FunctionComponent.Of for different cases and they result in the same cacheKey. So it picks a wrong function at runtime for all cases but one.

At least the displayName should also be part of the cacheKey (I pass a custom value anyway) or accept optional custom cacheKey (although that would reveal its implementation).

None of the options is available which keeps me pinned to Fable.React 5.4.0 (last version before function caching was intorduced)

@DunetsNM
Copy link
Contributor Author

Actually my problem was that caller of the Of is also generic code.
So it's better to include 'Props type name into the cache key so there's no need to expose internal caching mechanism to library users (requires Of to become inline though).

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

No branches or pull requests

1 participant