-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
with-reasonml example errors when using 6.0.0-canary.6 #4202
Comments
Digging deeper I was able to identify an issue in I will send a PR to |
@tmepple Are you still using reasonml with next.js? I have a reasonml page I need to pass the context into to know what the query parameters are in the url of that page. Have you figured out how to use getInitialProps with ReasonML and nextjs reason pages? (My "plan B" is leaving my _app.js as plain javascript and then passing stuff from that getInitialProps to |
I was able to get context in getInitialProps in a pure ReasonML page following the instructions here: #4217 (comment) 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); |
Wow...that works! Thank you so much. I will get that into the example since it is likely to be something next reasonml users may eventually need to do and implementation is a bit complex for new users to work out on their own. Speaking of next with reasonml, would you happen to be able to provide any feedback about this: #5049. |
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 https://reasonml.github.io/docs/en/mutation |
The current reasonml needs an example of how to do getInitialProps. tmepple posted the only known way of doing it in [this comment](#4202 (comment)). It is unlikely reasonml users are going to discover that comment or figure it out on their own so having it in an example is critical. Also, dependencies updated. After updating dependencies, I get this error: ``` ModuleBuildError: Module build failed (from ./node_modules/next/dist/build/webpack/loaders/next-babel-loader.js): [1] Error: Cannot find module '@babel/core' [1] babel-loader@8 requires Babel 7.x (the package '@babel/core'). If you'd like to use Babel 6.x ('babel-core'), you should install 'babel-loader@7'. ``` Seems like @babel/core is required as peer dependency per [this comment](babel/gulp-babel#124 (comment)) so I added it. The way to do getInitialProps has changed in 7.0.2 canary so this also has a comment in the code about what change is required to get that working.
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.Expected Behavior
The
with-reasonml
example should work in v6 canary as it did under v5.xCurrent Behavior
Steps to Reproduce (for bugs)
yarn create next-app --example with-reasonml with-reasonml-app
cd with-reasonml-app
yarn && yarn dev
localhost:3000
It works!package.json
to6.0.0-canary.6
then runyarn
andyarn dev
againlocalhost:3000
and get the following error:Context
Was wanting to test the new
_app.js
functionality to see if it makes usinggetInitialProps
to load Apollo queries easier to use for pages implemented in ReasonML. Currently it's difficult/impossible to bind to the staticgetInitialProps
from Reason pages.Your Environment
The text was updated successfully, but these errors were encountered: