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

Addon-contexts: Fix 'cannot read property h of undefined' in preact #9001

Merged
merged 1 commit into from
Nov 29, 2019
Merged

Addon-contexts: Fix 'cannot read property h of undefined' in preact #9001

merged 1 commit into from
Nov 29, 2019

Conversation

squidfunk
Copy link
Contributor

@squidfunk squidfunk commented Nov 28, 2019

When trying to setup addon-contexts with Preact, I encountered the following error:

Cannot read property 'h' of undefined
TypeError: Cannot read property 'h' of undefined
    at renderPreact (http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:202:45)
    at wrapper (http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:36:12)
    at http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:2318:14
    at http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:2342:46
    at http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:1849:21
    at http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:3151:14
    at http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:3152:16
    at wrapper (http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:1432:12)
    at http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:2318:14
    at http://localhost:50903/vendors~main.61fc4c3beec8040aebff.bundle.js:2332:26

This is due to the fact that preact is imported with a synthetic default import. This forces the user to enable allowJs and allowSyntheticDefaultImports in tsconfig.json which conflicts with declaration.

What I did

Changed the import to a proper destructuring import (same as for React):

import { createElement, ReactElement } from 'react';

@vercel
Copy link

vercel bot commented Nov 28, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

Copy link

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, this should do the job 👍 💯 I can confirm that we dropped the default export starting with version 10 and only supported named exports. This PR addresses that 🥇

On top of that this change is backwards compatible with the 8.x release line.

Disclaimer: I'm part of the Preact team.

@shilman shilman changed the title Fix 'cannot read property h of undefined' Preact: Fix 'cannot read property h of undefined' Nov 29, 2019
@shilman shilman changed the title Preact: Fix 'cannot read property h of undefined' Addon-contexts: Fix 'cannot read property h of undefined' in preact Nov 29, 2019
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shilman shilman added addon: contexts preact bug patch:yes Bugfix & documentation PR that need to be picked to main branch labels Nov 29, 2019
@shilman shilman added this to the 5.2.x milestone Nov 29, 2019
@shilman shilman merged commit a3b5d42 into storybookjs:next Nov 29, 2019
@shilman shilman added the patch:done Patch/release PRs already cherry-picked to main/release branch label Nov 30, 2019
shilman added a commit that referenced this pull request Nov 30, 2019
Addon-contexts: Fix 'cannot read property h of undefined' in preact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: contexts bug patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch preact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants