Skip to content

Commit 5e3e0e9

Browse files
committed
relax conditions on record type export #666
1 parent afdc9fb commit 5e3e0e9

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/Feliz.CompilerPlugins/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Relax validation of record props defined along the react component to allow lower cased record types #463 #666 by @melanore
13+
1014
## 3.0.0-rc.1 - 2025-09-18
1115

1216
### Added

src/Feliz.CompilerPlugins/ReactComponent.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ type ReactComponentAttribute(?exportDefault: bool, ?import: string, ?from:string
244244
if decl.Args.Length = 1 && AstUtils.isRecord compiler decl.Args[0].Type then
245245
// check whether the record type is defined in this file
246246
// trigger warning if that is case
247-
let definedInThisFile =
247+
let definedInThisFileAndIsUpperCase =
248248
file.Declarations
249249
|> List.tryPick (fun declaration ->
250250
match declaration with
@@ -253,7 +253,9 @@ type ReactComponentAttribute(?exportDefault: bool, ?import: string, ?from:string
253253
match decl.Args[0].Type with
254254
| Type.DeclaredType (entity, _genericArgs) ->
255255
let declaredEntity = compiler.GetEntity(entity)
256-
if classEntity.IsFSharpRecord && declaredEntity.FullName = classEntity.FullName
256+
if classEntity.IsFSharpRecord
257+
&& declaredEntity.FullName = classEntity.FullName
258+
&& (System.Char.IsUpper declaredEntity.CompiledName.[0])
257259
then Some declaredEntity.FullName
258260
else None
259261

@@ -265,12 +267,12 @@ type ReactComponentAttribute(?exportDefault: bool, ?import: string, ?from:string
265267
None
266268
)
267269

268-
match definedInThisFile with
270+
match definedInThisFileAndIsUpperCase with
269271
| Some recordTypeName ->
270272
let errorMsg = String.concat "" [
271273
sprintf "Function component '%s' is using a record type '%s' as an input parameter. " decl.Name recordTypeName
272274
"This happens to break React tooling like react-refresh and hot module reloading. "
273-
"To fix this issue, consider using an anonymous record instead or multiple simpler values as input parameters (can be tupled). "
275+
"To fix this issue, consider using instead: a lowercased record type, an anonymous record or multiple simpler values as input parameters (can be tupled). "
274276
"Future versions of [<ReactComponent>] might not emit this warning anymore, in which case you can assume that the issue is fixed. "
275277
"To learn more about the issue, see https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/258"
276278
]

tests/Feliz/ExtractChildren.test.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ describe "HtmlHelper.createElement" <| fun _ ->
133133
"children", box child
134134
]
135135
let extractedProps, childOption = HtmlHelper.extractByKeyFast "children" props
136-
Browser.Dom.console.log(extractedProps)
137-
Browser.Dom.console.log(childOption)
138136
expect(child).toBeTruthy()
139137
let key, child =
140138
match childOption with

0 commit comments

Comments
 (0)