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

@bem-react/di: problem with using Preact X #496

Open
belozer opened this issue Oct 20, 2019 · 2 comments
Open

@bem-react/di: problem with using Preact X #496

belozer opened this issue Oct 20, 2019 · 2 comments
Labels

Comments

@belozer
Copy link
Member

belozer commented Oct 20, 2019

Preact version: 10.0.1

Example:

import { Registry, withRegistry, useComponentRegistry } from '@bem-react/di'

const registry = new Registry({ id: 'my-reg'})
registry.set('Button', (props) => <button {...props} />)

const Index = () => {
    const { Button } = useComponentRegistry('my-reg')
    return(
        <div>
            <h1>Hello World</h1>
            <Button type='link'>Hello!</Button>
        </div>
    )
}

export default withRegistry(registry)(Index)

Error

Cannot read property 'my-reg' of undefined
TypeError: Cannot read property 'my-reg' of undefined
    at /home/sergey/Sandbox/nextjs-preactX/node_modules/@bem-react/di/build/di.development.js:33:54
    at Array.forEach (<anonymous>)
    at Object.children (/home/sergey/Sandbox/nextjs-preactX/node_modules/@bem-react/di/build/di.development.js:32:28)
    at Object.Consumer (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact/dist/preact.js:1:8457)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:1990)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at u (/home/sergey/Sandbox/nextjs-preactX/node_modules/preact-render-to-string/dist/index.js:1:2107)
    at render (/home/sergey/Sandbox/nextjs-preactX/node_modules/next-server/dist/server/render.js:79:16)
    at renderPage (/home/sergey/Sandbox/nextjs-preactX/node_modules/next-server/dist/server/render.js:255:20)
    at /home/sergey/Sandbox/nextjs-preactX/.next/server/static/development/pages/_document.js:437:17

See demo repository (pages/index.jsx)
https://github.com/belozer/nextjs-with-bem-react-preact-bug

@belozer belozer changed the title @bem-react/di: bug with using Preact @bem-react/di: bug with using Preact X Oct 20, 2019
@belozer belozer changed the title @bem-react/di: bug with using Preact X @bem-react/di: problem with using Preact X Oct 20, 2019
@yarastqt yarastqt added the bug label Oct 20, 2019
@belozer
Copy link
Member Author

belozer commented Oct 20, 2019

After change file

@bem-react/di/build/di.development.js
return (React.createElement(RegistryConsumer, null, function (contextRegistries) {

to

return (React.createElement(RegistryConsumer, null, function (contextRegistries = {}) {

The problem disappeared. Maybe it's a Preact bug.

@yarastqt
Copy link
Member

yarastqt commented Mar 1, 2020

Актуально ещё?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants