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.

Uncaught Error: Unable to find element with ID with server side rendering

See original GitHub issue

Everything works fine, except when doing initial page load via server side rendering. The error only occurs if I place anything inside the <Map></Map>.
If I use client side rendering, everything works as expected.
My situation is something similar to:

let ReactMapboxGl
let Map
let ZoomControl

if (window) {
  ReactMapboxGl = require('react-mapbox-gl')
  ZoomControl = ReactMapboxGl.ZoomControl 
  Map = ReactMapboxGl.Map({
    accessToken: '...',
    scrollZoom: false,
  })
}

...

render() {
  return Map &&
    <Map style="...">
      <ZoomControl />
    </Map>
}

The reason of the error is explained here https://github.com/facebook/react/issues/7093 . But I’m guessing there needs to be a solution for react-mapbox-gl to work with server side rendering. Any help is greatly appreciated!

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jthetzelcommented, Jan 7, 2018

Which version of React is installed? The error is supposed to go away in React 16 ( https://github.com/facebook/react/issues/7093#issuecomment-333512582 ).

1reaction
n23danielcommented, Jan 8, 2018

Thanks for the componentDidMount tip. I’ve previously rendered using a CLIENT global variable I set during file compilation, server or client bundle. I still don’t fully understand why the check after componentDidMount works instead of checking only if it’s client before it mounts. Maybe React allows dom updates after component did mount, but not before as it already has the server’s dom with react ids. Anyways, Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Receiving "Uncaught Error: Unable to find element with ID 15 ...
I've identified the element with this ID as being a imported from react-router-dom. I did find GitHub issues describing similar errors (one and ......
Read more >
Using Cypress - Cypress Documentation
How do I get the native DOM reference of an element found using Cypress? ... from failing my test when my application throws...
Read more >
NG8001: Unknown HTML element or component - Angular
Use the element name in the error to find the file(s) where the element is being used. Check that the name and selector...
Read more >
Tag: Server-side Rendering - somewhat abstract
If all goes well and I remember what my fix was going to be, we will have a successfully server-side rendered application that...
Read more >
Client Side Development with Spring Boot Applications
It is very easy to use and well suited to server-side rendering because it ... To get started with Spring Boot and client-side...
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