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

Multilevel Sort fails on Safari 14 - Object.hasOwn is not a function #6

Closed
lorenwest opened this issue Oct 27, 2022 · 2 comments
Closed

Comments

@lorenwest
Copy link

When running Storybook with storybook-multilevel-sort on a Safari v14 browser, the error at the bottom of this post is shown.

The issue is simple - Safari v14 doesn't have an object.hasOwn() method.

It's pretty easy to workaround by adding the following polyfill before loading storybook-multilevel-sort

('hasOwn' in Object) || (Object.hasOwn = Object.call.bind(Object.hasOwnProperty));

The solution is to use Object.hasOwnProperty() instead of Object.hasOwn() in the following code

const hasKey = (obj, key) => Object.hasOwn(obj, key);

I'd be happy to have the code authors make this change, or I could issue a pull request. The fix doesn't appear to cause any backward compatibility issues.

Here's the full text of the error in case someone lands on this issue from a search. Also attached a screen shot of how this looks on a Safari v14 browser.

Error sorting stories with sort parameter function storySort(story1, story2) {
      return Object(storybook_multilevel_sort__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(order, story1, story2);
    }:

> Object.hasOwn is not a function. (In 'Object.hasOwn(obj, key)', 'Object.hasOwn' is undefined)

Are you using a V7-style sort function in V6 compatibility mode?

More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#v7-style-story-sort

Screen Shot 2022-10-27 at 10 34 36 AM

@jgornick
Copy link

We are also running into this issue when sorting for in a node/React Native environment.

prantlf added a commit that referenced this issue Nov 27, 2022
github-actions bot pushed a commit that referenced this issue Nov 27, 2022
## [1.1.1](v1.1.0...v1.1.1) (2022-11-27)

### Bug Fixes

* Support browsers without Object.hasOwn ([b67cfef](b67cfef)), closes [#6](#6)
@prantlf
Copy link
Owner

prantlf commented Nov 27, 2022

Thank you very much for an exhaustive description of the problem! I use Safari myself, but the latest version.

I added a fallback to Object.prototype.hasOwnProperty, according to the description of Object.hasOwn at MDN.

The fix got released as 1.1.1.

@prantlf prantlf closed this as completed Nov 27, 2022
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

3 participants