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.

`renderArgs.elements` is empty when navigating to the same route

See original GitHub issue

In my app I sometimes have links from a route to the same route, but with different pathname. Those are forum Thread pages: one thread could link to another thread. In some previous versions renderArgs.elements seemed to be always present, so my workaround of doing:

renderArgs.elements[renderArgs.elements.length - 1] = 
  React.cloneElement(renderArgs.elements[renderArgs.elements.length - 1], {
    key: renderArgs.location.pathname
  })

seemed to work. It doesn’t seem to work anymore, because when navigating from a thread to another thread renderArgs.elements seems to be undefined. Could it be the case? If yes, perhaps could you propose any potential workaround for this case? My current workaround is creating a wrapper over Thread page component that would set a key on the wrapped Thread page — seems to work.

export default function ThreadPageWrapper() {
  const board = useSelector(({ chan }) => chan.board)
  const thread = useSelector(({ chan }) => chan.thread)
  return <ThreadPage key={`${board.id}/${thread.id}`}/>
}

ThreadPageWrapper.meta = ThreadPage.meta
ThreadPageWrapper.load = ThreadPage.load

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
taioncommented, Dec 19, 2019

yeah, makes sense. i think something like the static container approach we have right now is the best possible without suspense, but it doesn’t fully work with redux.

suspense makes all of this much easier. some day…

1reaction
taioncommented, Dec 18, 2019

Ah, okay – in that place, elements is not necessarily defined. Reference https://github.com/4Catalyzer/found/blob/2b439b6f509c932f3a100f1deffed667b6dd55a6/src/createRender.js#L13-L34 – we could be in the “pending” or “error” branch. I’d just wrap your logic above in an if block.

If you were using createRender more-or-less directly to generate the render function to pass into one of the routers, then you could also just put the logic in renderFetched there, but it looks like you have enough custom logic that it’d probably be easier just to use the if (renderArgs.elements) in here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Matched leaf route at location "/" does not have an element
In V6, you can't use the component prop anymore. It was replaced in favor of element : <Route path="/" element={<Home />}></Route>.
Read more >
[v6-alpha.3] Route with empty path does not render nested ...
The use case is to render a common layout component for all routes, then a route component for index path. <Route path="" element={< ......
Read more >
found - npm
Extensible route-based routing for React applications. ... In components rendered by the router, use <Link> to render links that navigate ...
Read more >
NavController | Android Developers
static final void ... Navigate to a route in the current NavGraph. ... This assumes that the current graph shares the same hierarchy...
Read more >
Layouts and Rendering in Rails - Ruby on Rails Guides
This method takes exactly the same options as render , but it returns a ... You can also do that with render ,...
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