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

TypeError: state.talkback is not a function #206

Closed
MoOx opened this issue Aug 27, 2020 · 8 comments
Closed

TypeError: state.talkback is not a function #206

MoOx opened this issue Aug 27, 2020 · 8 comments
Labels
question Further information is requested

Comments

@MoOx
Copy link

MoOx commented Aug 27, 2020

Hi, I am having issue with next & getStaticProps. I am getting a weird wonka runtime error.
Here is a sample of my code (still WIP)

let getStaticProps: Next.GetStaticProps.t(props, {.}) =
  _context => {
    let request =
      GetItems.make(
        ~first=perPage,
        ~pageSlug="noop",
        ~categorySlug="",
        // ~tagSlug=None,
        // ~cursorAfter=None,
        (),
      );

    Client.query(~client=Graphql.client, ~request, ())
    |> Js.Promise.then_(data => {
         switch (Client.(data.response)) {
         | Data(d) =>
           {"props": makeProps(~items=Js.Nullable.return(d), ())}
           ->Js.Promise.resolve
         | Error(e) =>
           {"props": makeProps(~items=Js.Nullable.null, ())}
           ->Js.Promise.resolve
         | Empty =>
           {"props": makeProps(~items=Js.Nullable.null, ())}
           ->Js.Promise.resolve
         }
       })
    |> Js.Promise.catch(err => {
         Js.log2("Failure!!", err);
         {"props": makeProps(~items=Js.Nullable.null, ())}
         ->Js.Promise.resolve;
       });
  };

Here is the runtime error I got

Failure!! TypeError: state.talkback is not a function
    at _0 (webpack-internal:///./node_modules/wonka/src/operators/wonka_operator_take.js:62:28)
    at eval (webpack-internal:///./node_modules/wonka/src/operators/wonka_operator_takeLast.js:18:18)
    at eval (webpack-internal:///./node_modules/wonka/src/wonka_helpers.js:21:12)
    at eval (webpack-internal:///./node_modules/wonka/src/operators/wonka_operator_take.js:50:14)
    at Module._1 (webpack-internal:///./node_modules/bs-platform/lib/es6/curry.js:55:12)
    at Module.captureTalkback (webpack-internal:///./node_modules/wonka/src/wonka_helpers.js:16:73)
    at eval (webpack-internal:///./node_modules/wonka/src/operators/wonka_operator_takeLast.js:10:79)
    at Module._1 (webpack-internal:///./node_modules/bs-platform/lib/es6/curry.js:55:12)
    at eval (webpack-internal:///./node_modules/wonka/src/web/wonka_sink_toPromise.js:10:75)
    at new Promise (<anonymous>)

I have no clue on how to fix this problem...

@parkerziegler
Copy link
Contributor

Hey @MoOx, sorry to hear you're having issues – that's a pretty bizarre runtime error to be hitting. Your code looks correct to me (assuming that GraphQL.client is your urql client instance). Can you try the following:

  • Switch to using Client.executeQuery and Wonka.subscribe and see if the issue persists? This should help us figure out if there's an issue in our implementation of Client.query. You can see an example of this here.
  • Can you paste the compiled ReScript (BuckleScript) output of the original sample (the code above) here? I want to see if, with the compiled JS in hand, we can better narrow down the runtime error.

My guess is one of two things:

  • It may be related to running in a Node environment. getStaticProps will run on the server only at build time. We haven't verified reason-urql in that environment – we've only verified that binding to next-urql can work for getInitialProps.
  • It may be related to the version of wonka that comes along with the urql v1.7.0. I wouldn't expect that, but you never know. Looking at the source, the talkbackPlaceholder is defined here: https://github.com/kitten/wonka/blob/v3.2.1/src/wonka_helpers.re#L3 in v3.2.1 (which urql v1.7.0 uses) and should be compiled to a noop function just fine.

Please give the steps above a shot. I'll try to get a minimal reproduction going as well once I hear back from you. Thanks!

@parkerziegler parkerziegler added the question Further information is requested label Aug 30, 2020
@gaku-sei
Copy link

gaku-sei commented Sep 8, 2020

Hey @MoOx @parkerziegler , just so you know, this error is very likely related to Wonka and it happens with BuckleScript > 8.0.
It's been reported here: 0no-co/wonka#85, and fixed here: 0no-co/wonka#88

Wonka 5.0.0-rc does fix it. That being said, since urql and reason urql are using Wonka 4* it's a bit hard to update to BS > 8.0 with Reason Urql now 😕 (is it worth having an issue?)

@MoOx
Copy link
Author

MoOx commented Sep 11, 2020

Thanks for the notice @gaku-sei ! I guess I will revert bs until this is fixed :)

@parkerziegler
Copy link
Contributor

@MoOx I'd be curious if you'd be able to use yarn resolutions to force your wonka version to v5.0.0-rc.0. If you're using yarn you should be able to add the following to your package.json:

{
  "resolutions": {
    "wonka": "5.0.0-rc.0"
  }
}

reason-urql uses whatever version of wonka is shipped with the urql version it binds to. So by using resolutions, you could force wonka v5 to be resolved. It's not guaranteed it'll work (urql hasn't been tested against that version), but may be worth a quick shot.

@kitten any timeline on upgrading urql core to use wonka v5?

@kitten
Copy link

kitten commented Sep 11, 2020

@parkerziegler I don't have any timeline yet. The problem is that it's a change that'll need to happen across all packages as there's no path for backwards compatibility; When a user has multiple @urql/* packages installed but doesn't upgrade all of them then this will potentially break. So we're basically delaying this ... because we're afraid of what may happen 😆

For now, all I can recommend is to stick to Wonka 4 and BuckleScript <8.0, or to use BuckleScript >=8.0 and to use a resolution.

@MoOx
Copy link
Author

MoOx commented Sep 12, 2020

Note sure what's happening today to me... I just tried to get back on this topic (I am migrating a site that where using reason-apollo and and old ssg to next+reason+urql).
I deleted my yarn.lock+node_modules, installed reason-url (got 2.1.0-rc0) and I am getting

Error: package gentype not found or built
- Did you install it?
- If you did, did you run `bsb -make-world`?

I am not using gentype by my own. Is this Wonka or something else that's needs it?

@parkerziegler
Copy link
Contributor

parkerziegler commented Sep 12, 2020

wonka does use genType under the hood. Did you try including wonka in your bs-dependencies array? All of our examples do that but I'm realizing we don't have that documented anywhere 😞 If that does indeed fix your issues I'll add it to the formal documentation steps.

@parkerziegler
Copy link
Contributor

👋 Hey folks, the fix for this has been merged into main and released on v3.0.0-rc.0. Docs are in the README for using yarn resolutions to resolve a compatible wonka version: https://github.com/FormidableLabs/reason-urql#1a-important-note-for-users-of-bs-platform800

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

No branches or pull requests

4 participants