diff --git a/compiler/crates/react_compiler_hir/src/default_module_type_provider.rs b/compiler/crates/react_compiler_hir/src/default_module_type_provider.rs index 38668a8bc3e3..448ba5ee816d 100644 --- a/compiler/crates/react_compiler_hir/src/default_module_type_provider.rs +++ b/compiler/crates/react_compiler_hir/src/default_module_type_provider.rs @@ -77,22 +77,42 @@ pub fn default_module_type_provider(module_name: &str) -> Option { })), "@tanstack/react-virtual" => Some(TypeConfig::Object(ObjectTypeConfig { - properties: Some(IndexMap::from_iter([( - "useVirtualizer".to_string(), - TypeConfig::Hook(HookTypeConfig { - positional_params: Some(Vec::new()), - rest_param: Some(Effect::Read), - return_type: Box::new(TypeConfig::TypeReference(TypeReferenceConfig { - name: BuiltInTypeRef::Any, - })), - return_value_kind: None, - no_alias: None, - aliasing: None, - known_incompatible: Some( - "TanStack Virtual's `useVirtualizer()` API returns functions that cannot be memoized safely".to_string(), - ), - }), - )])), + properties: Some(IndexMap::from_iter([ + ( + "useVirtualizer".to_string(), + TypeConfig::Hook(HookTypeConfig { + positional_params: Some(Vec::new()), + rest_param: Some(Effect::Read), + return_type: Box::new(TypeConfig::TypeReference(TypeReferenceConfig { + name: BuiltInTypeRef::Any, + })), + return_value_kind: None, + no_alias: None, + aliasing: None, + known_incompatible: Some( + "TanStack Virtual's `useVirtualizer()` API returns functions that cannot be memoized safely".to_string(), + ), + }), + ), + // `useWindowVirtualizer()` wraps the same virtualizer instance as `useVirtualizer()`, + // so its return value is incompatible for the same reason. + ( + "useWindowVirtualizer".to_string(), + TypeConfig::Hook(HookTypeConfig { + positional_params: Some(Vec::new()), + rest_param: Some(Effect::Read), + return_type: Box::new(TypeConfig::TypeReference(TypeReferenceConfig { + name: BuiltInTypeRef::Any, + })), + return_value_kind: None, + no_alias: None, + aliasing: None, + known_incompatible: Some( + "TanStack Virtual's `useWindowVirtualizer()` API returns functions that cannot be memoized safely".to_string(), + ), + }), + ), + ])), })), _ => None, diff --git a/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts b/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts index 106fce615c44..0a7a728c1fa2 100644 --- a/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts +++ b/compiler/packages/babel-plugin-react-compiler/src/HIR/DefaultModuleTypeProvider.ts @@ -101,6 +101,17 @@ export function defaultModuleTypeProvider( returnType: {kind: 'type', name: 'Any'}, knownIncompatible: `TanStack Virtual's \`useVirtualizer()\` API returns functions that cannot be memoized safely`, }, + /* + * `useWindowVirtualizer()` wraps the same virtualizer instance as `useVirtualizer()`, so its return value + * is incompatible for the same reason and we mark the entire hook as incompatible + */ + useWindowVirtualizer: { + kind: 'hook', + positionalParams: [], + restParam: Effect.Read, + returnType: {kind: 'type', name: 'Any'}, + knownIncompatible: `TanStack Virtual's \`useWindowVirtualizer()\` API returns functions that cannot be memoized safely`, + }, }, }; }