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

Cannot set property className of #<Object> which has only a getter #1356

Open
belhassen07 opened this issue May 26, 2020 · 16 comments
Open

Cannot set property className of #<Object> which has only a getter #1356

belhassen07 opened this issue May 26, 2020 · 16 comments

Comments

@belhassen07
Copy link

catch-error.js?88ae:35 Uncaught TypeError: Cannot set property className of #<Object> which has only a getter
    at DialogFooterButton.render (MaterialComponent.js?de07:46)

"preact": "^10.1.0"
"preact-cli": "^3.0.0-rc.6"

@kontrollanten
Copy link
Contributor

@belhassen07 Did you find any solution for this?

@belhassen07
Copy link
Author

@kontrollanten I actually ditched the whole package.

@kontrollanten
Copy link
Contributor

@belhassen07 Okay, thanks for letting me know. Did you find any other package that could be used with preact?

@belhassen07
Copy link
Author

I used @zeit-ui/react which pretty good for my use case and backed by the company. Other than that, it turns out you can use @material-ui with preact, you gotta be careful with bundle size though (meaning use only what you can't recreate easily: Modal? use it, button? probably not, that's my thought process anyway). I hope this helps.

@jsumnerPhD
Copy link

I have the same issue with DialogFooterButton. I have also come across this error when using IconButtons, but inconsistently. Any luck finding workarounds?

@prateekbh
Copy link
Owner

Sorry for the trouble caused.
I am not being able to dedicate more time to maintain this project. I'd be more than happy to call this deprecated.
As fr this issue I suggest pinning the mdc-web dependency to a strict number.
Also the project might not work for PreactX and above

@jsumnerPhD
Copy link

@prateekbh Sorry to hear that! It is a nice project that (in my experience so far) makes combining mdc with PreactX almost seamless.

@jsumnerPhD
Copy link

Just fyi - After some poking around, the problem seems to stem from here:

<button {...props} className="mdc-button" ref={this.setControlRef}>

Removing the className attribute here and re-building (and then specifying className on the component directly) removes this error.

@prateekbh Any hints as to why this might be problematic?

@jsumnerPhD
Copy link

jsumnerPhD commented Jul 22, 2020

Changing:

element[propName].className = `${userDefinedClasses} ${this.getClassName(

To: element[propName].class resolves the issue.

@prateekbh
Copy link
Owner

in your app code are you using class or className?

@jsumnerPhD
Copy link

Neither really, I am inserting the component "as-is":

<Dialog.Footer>
    <Dialog.FooterButton cancel={true}>Decline</Dialog.FooterButton>
    <Dialog.FooterButton accept={true}>Accept</Dialog.FooterButton>
</Dialog.Footer>

@jsumnerPhD
Copy link

@prateekbh I made the PR to show the proposed change... I am not sure it is the best solution though.

@prateekbh
Copy link
Owner

Are you using this with preactX or preact8?
This intentionally uses className and the user application is supposed to stick to className as well

@jsumnerPhD
Copy link

I am using "preact": "^10.4.5" with className not class. Setting className on a component from app code works perfectly. The error seems to be thrown from the library. Indeed, the Cannot set property className of #<Object> which has only a getter error seems to be raised on Dialog.FooterButton only if we set className="mdc-button" from preact-material-components/ts/Dialog/index.tsx. Removing className there and setting it from the app does not throw the error.

@prateekbh
Copy link
Owner

Master is not ready for preactX and above there is a separate branch for 2.0 but we never reached a stable state in that branch.

@jsumnerPhD
Copy link

Ok, I get it. For anyone stumbling across this thread, I found rmwc was a good alternative.

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

4 participants