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

Revert "feat(vanilla): Support class fields (defineProperty) (#760)" #766

Merged
merged 1 commit into from
Jul 27, 2023

Conversation

pastelmind
Copy link
Contributor

@pastelmind pastelmind commented Jul 24, 2023

This reverts commit c0bda5a.

Due to what I presume is a bug in the Hermes engine, React Native projects cannot use Valtio 1.11.0. Let's revert #760 to support existing React Native users.

Related Issues or Discussions

Fixes #765
May fix #764 (but we need confirmation from actual RN users)

Summary

This reverts #760 (c0bda5a). The following pattern (described in detail at #759) is no longer explicitly supported:

class ValtioProxy {
  constructor() {
    return proxy(this)
  }
}

class MyStore extends ValtioProxy {
  field1 = 'asdf' // OK
  field2 = []     // This works in v1.11.0.
                  // But when this PR is merged,
                  // the array will no longer be reactive
}

const store = new MyStore()
store.field2.push(1) // Will re-render views in v1.11.0
                     // but not after this PR is merged

To work around this, we can explicitly set the field in the constructor, which properly invokes the set proxy trap:

class MyStore extends ValtioProxy {
  constructor() {
    super()
    this.field2 = [] // This will be reactive
  }
}

Alternatively, you can configure your transpiler to use 'set' semantics for class fields (e.g. useDefineForClassFields: false. (Personally I advise against this, because it deviates from the modern ECMAScript spec)

Check List

  • yarn run prettier for formatting code and docs

)"

This reverts commit c0bda5a.

Due to what I presume is a bug in the Hermes engine, React Native
projects cannot use Valtio 1.11.0. Let's revert pmndrs#760 to support existing
React Native users.
@vercel
Copy link

vercel bot commented Jul 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
valtio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 24, 2023 4:35am

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 63b9cf6:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration

@dai-shi
Copy link
Member

dai-shi commented Jul 25, 2023

May fix #764 (but we need confirmation from actual RN users)

Is it now confirmed with #764 (reply in thread) ?

Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

The change looks good.

@pastelmind
Copy link
Contributor Author

May fix #764 (but we need confirmation from actual RN users)

Is it now confirmed with #764 (reply in thread) ?

I believe so.

@ivankdev
Copy link

Vote for this, when it could be merged?

@td-tomasz
Copy link

Is it worth reverting? Maybe the bug will be fixed in Hermes earlier.

@dai-shi
Copy link
Member

dai-shi commented Jul 26, 2023

It makes sense to revert as we didn't know such a limitation when we merged and released.
I don't disagree that this is a reasonable addition, but my assumption was it didn't hurt at all.

#760 (review)

Not sure if there are pitfalls, but this should be harmless for normal (plain objects) usage, except for the bundle size increase.

So, there is an unexpected pitfall and it's harmful for some users.

@dominiczaq
Copy link

dominiczaq commented Jul 26, 2023 via email

@dai-shi dai-shi merged commit 6eac2fc into pmndrs:main Jul 27, 2023
31 checks passed
@pastelmind pastelmind deleted the revert-760 branch July 28, 2023 15:16
pastelmind pushed a commit to pastelmind/valtio that referenced this pull request Jul 28, 2023
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

Successfully merging this pull request may close these issues.

defineProperty trap makes property non-CEW in React Native (Hermes engine)
5 participants