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

SizeSensor throws TypeError when child has style #42

Open
Ghirigoro opened this issue Mar 22, 2019 · 2 comments
Open

SizeSensor throws TypeError when child has style #42

Ghirigoro opened this issue Mar 22, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@Ghirigoro
Copy link

If you create a child with a style (even an empty one) like this:

    render() {
        return (
            <SizeSensor onSize={this.onResize}>
                <div style={{}}>
                    {this.props.children}
                </div>
            </SizeSensor>
        );
    }

SizeSensor throws the error below. Removing the style attribute fixes the issue.

react-dom.development.js:20266 Uncaught TypeError: Cannot assign to read only property 'position' of object '#<Object>'
    at SizeSensor.webpackHotUpdate../node_modules/libreact/lib/SizeSensor/index.js.SizeSensor.render (index.js:68)
    at finishClassComponent (react-dom.development.js:14695)
    at updateClassComponent (react-dom.development.js:14650)
    at beginWork (react-dom.development.js:15598)
    at performUnitOfWork (react-dom.development.js:19266)
    at workLoop (react-dom.development.js:19306)
    at renderRoot (react-dom.development.js:19389)
    at performWorkOnRoot (react-dom.development.js:20296)
    at performWork (react-dom.development.js:20208)
    at performSyncWork (react-dom.development.js:20182)
@streamich
Copy link
Owner

streamich commented Mar 22, 2019

@Ghirigoro Thanks, for reporting this. It must be because of this line:

https://github.com/streamich/libreact/blob/master/src/SizeSensor/index.ts#L85

React in development mode makes style object read-only, but on that line the .position property is mutated.

@streamich streamich added the bug Something isn't working label Mar 22, 2019
@Ghirigoro
Copy link
Author

@streamich Yeah. I was just looking at the source and changing that line to use a clone of the style property resolved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants