Good people, hello!
I have some hiccups getting my head around working with Relay. For some reason no data is passed to my Sidebar component. The data is available in my <script id="preloadedData">
node, but it's not getting passed to where it should go
client.js:
match({ routes, history: browserHistory }, (error, redirectLocation, renderProps) => {
if (error) throw error;
IsomorphicRouter.prepareInitialRender(environment, renderProps).then((props) => {
ReactDOM.render(
<Router {...props} />,
root
);
});
});
routes.js:
[{
path: '/',
component: App,
indexRoute: {
getComponents: (nextState, cb) => {
Promise.all([
System.import('./Home/Hero'),
System.import('./Home'),
System.import('../components/Sidebar')
])
.then(modules => cb(null, {
hero: modules[0].default,
content: modules[1].default,
sidebar: modules[2].default
}))
.catch((e) => { throw e; });
},
queries: {
sidebar: {
joke: () => Relay.QL`query Joke { randomJoke }`,
quote: () => Relay.QL`query Quote { randomQuote }`
}
}
}
}];
App.js - a regular stateless component (no relay wrapper)
<div className={s.root}>
{hero}
<main>
<Header />
{content}
{sidebar}
</main>
<Footer />
</div>
Sidebar.js
...
Relay.createContainer(Sidebar, {
fragments: {
joke: () => Relay.QL`
fragment on Joke {
text
}
`,
quote: () => Relay.QL`
fragment on Quote {
text,
author,
sourceUrl
}
`
}
});
Sidebar props:
{"history":{},"location":{"pathname":"/","search":"","hash":"","state":null,"action":"POP","key":"aelohd","query":{},"$searchBase":{"search":"","searchBase":""}},"params":{},"route":{"queries":{"sidebar":{}}},"routeParams":{},"routes":[{"path":"/","indexRoute":{"queries":{"sidebar":{}}},"childRoutes":[{"path":"/register","queries":{"content":{}}},{"path":"/publications","queries":{"content":{}}}]},{"queries":{"sidebar":{}}}],"children":null,"relay":{"pendingVariables":null,"route":{"name":"_aggregated___route_1_sidebar_joke___route_1_sidebar_quote","queries":{},"params":{}},"variables":{}}}
Additionally, the following error is displayed: RelayContainer: Expected prop 'joke' to be supplied to 'Sidebar', but got 'undefined'. Pass an explicit 'null' if this is intentional.
(same for quote
)
I have no idea what's wrong and I'll need your help, please!
The problem was combination of incorrect relay query usage and bug in isomorphic-relay-router: link to the issue