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

React Refresh seems to break when using function hoisting #28550

Closed
pie6k opened this issue Apr 6, 2020 · 3 comments
Closed

React Refresh seems to break when using function hoisting #28550

pie6k opened this issue Apr 6, 2020 · 3 comments
Labels
Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@pie6k
Copy link

pie6k commented Apr 6, 2020

I had some weird error:
TypeError: Attempted to set a non-object key in a WeakMap

when trying to return some component function 'before' it's defined using hoisting.

export function createFooComponent() {
  // note that I'm returning the function before it's code is written using hoisting
  return [FooComponent];
  function FooComponent() {
    return <Text>Foo</Text>
  }
}

const [MyFoo] = createFooComponent();

// then somewhere

<MyFoo />

If I dive a bit deeper into stack:

image

seems react-refresh/cjs/react-refresh-runtime.development.js tries to call createSignatureFunctionForTransform, then setSignature and then trying to assign undefined to allSignaturesByType which is WeakMap so undefined cannot be the key

If I reverse the operations (I return component after it's function is defined) it works just fine.

react-native info

System:
    OS: macOS 10.15.3
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 2.90 GB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.5.0 - /var/folders/dd/xmqm6lfx7v9gjsdyxjq689l80000gn/T/yarn--1586198757621-0.9114872849379967/node
    Yarn: 1.21.1 - /var/folders/dd/xmqm6lfx7v9gjsdyxjq689l80000gn/T/yarn--1586198757621-0.9114872849379967/yarn
    npm: 6.13.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.8.4 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 27, 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-29 | Google APIs Intel x86 Atom, android-Q | Android TV Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.6010548
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  Languages:
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: ^0.62.1 => 0.62.1
  npmGlobalPackages:
    *react-native*: Not Found
@react-native-bot react-native-bot added Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. and removed Needs: Triage 🔍 labels Apr 6, 2020
@github-actions
Copy link

github-actions bot commented Apr 6, 2020

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@stale
Copy link

stale bot commented Jul 5, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 5, 2020
@stale
Copy link

stale bot commented Jul 12, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jul 12, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants