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.

Shared data is not available when using the `withRouteData`

See original GitHub issue

Are you reporting a bug?

Yes. Shared data is not available in the props when using the withRouteData HOC in the build. While running in dev mode it does work as expected.

Environment

  1. react-static -V: 6.3.2
  2. node -v: v10.11.0
  3. npm -v: 6.4.1
  4. Operating system: macOS

Steps to Reproduce the problem

Base your steps off of any freshly installed react-static template!

  1. Add to one of the routes, eg. blog in the basic template:
sharedData: {
  foo: createSharedData({ bar: 'foobar' }) 
},
  1. Check the result using:
export default withRouteData(({ posts, foo }) => (
  <div>
    <h1>It's { foo.bar }.</h1>
    [...]
  1. yarn build which results in:
TypeError: Failed exporting HTML for URL blog (src/pages/blog.js):Cannot read property 'bar' of undefined

Expected Behavior

Successful build with <h1>It's foobar.</h1> on the blog page

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bram-lcommented, Feb 8, 2019

@tannerlinsley after some deep digging I think I found a solution myself! Please let me know if this makes any sense to you. Also, I took the liberty to remove the return value of the prefetch methods as it turned out to be unused and slightly confused as it was before. Another option would be to actually return the merged data form the prefetch method instead of mutating the routeInfo, but I’m afraid that would mean refactoring in quite a few places and way more complicate to make sure it won’t break anything…

1reaction
tannerlinsleycommented, Jan 23, 2019

No, it should function the original way. This does indeed look like a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit Test with route data not working on ASP.NET MVC 5 Web ...
It looks like in MVC 5 the Url property is created in a different way. I have introduced this line in my tests...
Read more >
react-static/api.md at master - GitHub
First we would use the createSharedData function and pass the data we want to share between our routes. Then in each route, we...
Read more >
Ultimate React Router v6 Guide
Now the final way you can share layouts with React Router is by wrapping child Route components in a parent Route that only...
Read more >
Dynamic guard redirects with route data in Angular - kirjai
Redirecting. In case the user is not authenticated and not allowed to view the /restricted route, we would like to navigate him somewhere...
Read more >
ActivatedRoute - Angular
Provides access to information about a route associated with a component that is ... will not cause the ActivatedRoute.data Observable to emit a...
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