question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

with-reasonml example errors when using 6.0.0-canary.6

See original GitHub issue

This example works fine when using the stable version v5.1 but causes an error when upgrading to the latest canary. It looks like it might be related to the new Babel v7 beta or the babel-plugin-bucklescript that is used but I couldn’t isolate/reproduce the problem in the other repo.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

The with-reasonml example should work in v6 canary as it did under v5.x

Current Behavior

Steps to Reproduce (for bugs)

  1. yarn create next-app --example with-reasonml with-reasonml-app
  2. cd with-reasonml-app
  3. yarn && yarn dev
  4. Navigate to localhost:3000 It works!
  5. Bump version of next in package.json to 6.0.0-canary.6 then run yarn and yarn dev again
  6. Navigate to localhost:3000 and get the following error:
screen shot 2018-04-23 at 5 14 01 pm

Context

Was wanting to test the new _app.js functionality to see if it makes using getInitialProps to load Apollo queries easier to use for pages implemented in ReasonML. Currently it’s difficult/impossible to bind to the static getInitialProps from Reason pages.

Your Environment

Tech Version
next 6.0.0-canary.6
node 9.4.0
OS MacOS 10.13.4
browser Chrome v65

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
tmepplecommented, Nov 15, 2018

@Enalmada

I was able to get context in getInitialProps in a pure ReasonML page following the instructions here: https://github.com/zeit/next.js/pull/4217#issuecomment-385228035

Here is an example of accessing the context to detect if we are rendering on the server and passing a boolean into your ReasonReact component. Hope this helps!

let make = (~onServer, _children) => {
/* component code goes here */ 
};

let default =
  ReasonReact.wrapReasonForJs(~component, jsProps => make(~onServer=jsProps##onServer, [||]));

let getInitialProps = context =>
  Js.Promise.make((~resolve, ~reject as _) => {
    let onServer =
      switch (Js.Nullable.toOption(context##req)) {
      | None => false
      | Some(_) => true
      };
    resolve(. {"onServer": onServer});
  });

let inject = [%bs.raw {| (cls, fn) => cls.getInitialProps = fn |}];

inject(default, getInitialProps);
0reactions
tmepplecommented, Nov 17, 2018

HI @Enalmada I looked at that other issue and not enough time right now to test the hypothesis but maybe it would work if you define a mutable ref(), feed that to initial state, then mutate it (using :=) in the reducer? Or maybe use a handler instead to mutate the counter variable in Counter.re external to the state? Hope this gives you some things to try.

https://reasonml.github.io/docs/en/mutation https://reasonml.github.io/reason-react/docs/en/react-ref (note this may be confusing since it is talking about react ref to get a reference to the DOM but it also uses a normal ocaml ref() and shows the use of handlers) https://reasonml.github.io/reason-react/docs/en/callback-handlers

Read more comments on GitHub >

github_iconTop Results From Across the Web

with-reasonml example - state variables not persisting in ...
cache, we've written a custom webpack plugin that changes this behavior to share module instances between pages." Is that related at all to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found