You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It works if I use static html with no inputs, but adding the the 3 input attributes: init.props <- {| ... |} results in the following error:
LitElement.fs:275
Uncaught TypeError: Cannot set property name of #<classExpr> which has only a getter
at LitElement.fs:275:35
at Seq.js:837:9
at fold (Seq.js:691:19)
at iterate (Seq.js:836:5)
at initProps (LitElement.fs:274:40)
at new LitHookElement$1 (LitElement.fs:185:8)
at new classExpr (LitElement.fs:288:29)
at TemplateInstance._clone (lit-html.ts:927:52)
at ChildPart._commitTemplateResult (lit-html.ts:1270:33)
at ChildPart._$setValue (lit-html.ts:1165:12)
I was able to track down the issue, @alfonsogarciacaroname is a valid property and it should not throw in that case
inside Hook.fs we use some class expressions to make classes extensible
moduleinternalHookUtil =let [<Literal>]RENDER_FN_CLASS_EXPR="""class extends $0 { constructor() { super($2...) } get renderFn() { return $1 } // name is not defined here so no problem }"""let [<Literal>]HMR_CLASS_EXPR="""class extends $0 { constructor() { super($3...) } // this defines only a getter not a setter get name() { return $2; } // hence why it throws get renderFn() { return $1.value; } set renderFn(v) { $1.value = v; this.hooks.requestUpdate(); } }"""
In LitElement.fs we're using a class expression for HMR
typeLitElementAttribute(name: string)=/// ... more code ...
config.InitPromise
|> Promise.iter (fun _ ->letconfig= config :> LitConfig<obj>letstyles=if isNotNull config.styles then List.toArray config.styles |> Some
else None
letpropsOptions,initProps =if isNotNull config.props then// ... more code ...letinitProps(this:obj)=// this is where it fails// it tries to assign this['name'] = v// but in the class expression we only define a getter
propsValues |> Seq.iter(fun(k,v)->
this?(k)<- v)
Some propsOptions, initProps
else
None,fun _ ->()letclassExpr=letbaseClass= jsConstructor<LitHookElement<obj>>#if!DEBUG
// no `name` getter/setter defined hence it doesn't throw
emitJsExpr (baseClass, renderFn, initProps) HookUtil.RENDER_FN_CLASS_EXPR
#elseletrenderRef= LitBindings.createRef()
renderRef.value <- renderFn
// in this case the JS expression used has a `name` getter only
emitJsExpr (baseClass, renderRef, mi.Name, initProps) HookUtil.HMR_CLASS_EXPR
#endif// ... more code
If I comment the else from the DEBUG portion the error goes away,
If I use the HMR_CLASS_EXPR then the error comes back
I guess the ideal would be to use a different property like __name but I'm not sure if that is a breaking change for HMR
Oh! Thanks a lot for investigating the issue @AngelMunoz! You're right, I remembered now that name is used to identify the component when cherry-picking the exports of the new module in HMR here and here.
I don't remember if there was a specific reason to pick name, __name as you suggest should work too and have less chances of conflict.
This was fixed in 6317d3a and released in 1.4.2 (see "Fix #31: Conflict with name attribute" in the release notes). The HMR class expression now uses __name instead of name, so a name prop no longer collides with it. Closing, and thanks @AngelMunoz for tracking down the cause!
Activity
JordanMarr commentedon May 14, 2022
I think I was using reserved attribute names. Changing them fixed it!
AngelMunoz commentedon May 14, 2022
This probably shouldn't throw in those cases though, because AFAIK those are valid attribute names
AngelMunoz commentedon May 14, 2022
I'll try to investigate this if I have some bandwidth next week
alfonsogarciacaro commentedon May 17, 2022
Maybe
nameis causing problems. If that's the case we can try to identify it at runtime to throw a more meaningful error.AngelMunoz commentedon May 17, 2022
I was able to track down the issue, @alfonsogarciacaro
nameis a valid property and it should not throw in that caseinside
Hook.fswe use some class expressions to make classes extensibleIn
LitElement.fswe're using a class expression for HMRIf I comment the
elsefrom theDEBUGportion the error goes away,If I use the
HMR_CLASS_EXPRthen the error comes backI guess the ideal would be to use a different property like
__namebut I'm not sure if that is a breaking change forHMRalfonsogarciacaro commentedon May 24, 2022
Oh! Thanks a lot for investigating the issue @AngelMunoz! You're right, I remembered now that
nameis used to identify the component when cherry-picking the exports of the new module in HMR here and here.I don't remember if there was a specific reason to pick
name,__nameas you suggest should work too and have less chances of conflict.Solutions for #31 and #39
JordanMarr commentedon Oct 26, 2026
This was fixed in 6317d3a and released in 1.4.2 (see "Fix #31: Conflict with
nameattribute" in the release notes). The HMR class expression now uses__nameinstead ofname, so anameprop no longer collides with it. Closing, and thanks @AngelMunoz for tracking down the cause!