Skip to content

SizeSensor throws TypeError when child has style #42

Open
@Ghirigoro

Description

@Ghirigoro

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)

Activity

streamich

streamich commented on Mar 22, 2019

@streamich
Owner

@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.

Ghirigoro

Ghirigoro commented on Mar 22, 2019

@Ghirigoro
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      SizeSensor throws TypeError when child has style · Issue #42 · streamich/libreact