fix: support React.memo, forwardRef, and class components in all component props#2115
Open
naqvitalha wants to merge 1 commit intomainfrom
Open
fix: support React.memo, forwardRef, and class components in all component props#2115naqvitalha wants to merge 1 commit intomainfrom
naqvitalha wants to merge 1 commit intomainfrom
Conversation
c64981d to
12653d1
Compare
…onent props `getValidComponent` only checked `typeof component === "function"`, which excluded `React.memo` and `React.forwardRef` (both return objects). This caused `ListEmptyComponent`, `ListHeaderComponent`, `ListFooterComponent`, and `backdropComponent` to silently render nothing when passed a memoized component. Additionally, `renderScrollComponent` called class components as plain functions (via the `typeof === "function"` branch), which would throw at runtime since classes require instantiation. Changes: - Broaden `getValidComponent` to handle all non-null component types - Add `isComponentClass` utility to distinguish class components from render functions in the scroll component logic - Add `React.ExoticComponent` to the TypeScript types for all component props (ListEmptyComponent, ListHeaderComponent, ListFooterComponent, CellRendererComponent, ItemSeparatorComponent, renderScrollComponent, backdropComponent) Fixes #1983
12653d1 to
601b743
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getValidComponentonly checkedtypeof component === "function", silently droppingReact.memoandReact.forwardRefwrapped components (which are objects, not functions). This causedListEmptyComponent,ListHeaderComponent,ListFooterComponent, andbackdropComponentto render nothing when passed a memoized component.renderScrollComponentcalled class components as plain functions via the sametypeof === "function"branch, which would throw at runtime since classes requirenew/React.createElement.CellRendererComponent,ItemSeparatorComponent,renderScrollComponent, etc.) only acceptedReact.ComponentType, rejecting memo/forwardRef at the TypeScript level.Changes
componentUtils.tsgetValidComponentto handle all non-null component types; addedisComponentClassutilityuseSecondaryProps.tsxisComponentClassto avoid calling class scroll components as plain functionsFlashListProps.tsReact.ExoticComponentto all 7 component prop typescomponentUtils.test.tsxgetValidComponentandisComponentClassTest plan
yarn buildpassesyarn type-checkpassesyarn lintpassesyarn testpasses (177 tests, 14 suites)ListEmptyComponentrenders correctlyFixes #1983