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.

Tooltip cannot find ID of a React element rendered next to it

See original GitHub issue

Issue description

  • components: Tooltip
  • reactstrap version 5.0.0-alpha.4
  • import method umd, not full version
  • react version 16.2.0
  • bootstrap version 4.0.0-beta.3

What is happening?

Sometimes, when I render the attached code, I get this error: The target <target id> could not be identified in the dom, tip: check spelling. However, I can’t get the codepen to reproduce this, but it consistently happens in my larger application base, which uses the same data flow. The bug occurs when the button in the codepen is pressed, but perhaps React functions differently in my case. I made a small change in the codepen, the bug is now reproduceable.

The full application is here: https://github.com/kenzierocks/OurTube/blob/master/client/js/navbar.tsx#L78

I can help set this up to run if needed, but it’s still in the middle of initial development

What should be happening?

It should render my custom tooltip properly, with no errors.

Code

https://codepen.io/anon/pen/xpWJzN

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:19
  • Comments:42 (7 by maintainers)

github_iconTop GitHub Comments

81reactions
TheSharpieOnecommented, Mar 15, 2018

@yidingalan enzyme’s mount takes a second parameter; options. Options has a property, attachTo which is used to tell it where to mount the component. It’s not enough to add a div to the body, you have to then tell it to mount the component to that div.

it('test', () => {
  const div = document.createElement('div');
  document.body.appendChild(div);
  const wrapper = mount(<Component {...props} />, { attachTo: div });
});

More information about mount and it’s options: https://github.com/airbnb/enzyme/blob/master/docs/api/mount.md#mountnode-options--reactwrapper

16reactions
Cretezycommented, Jan 13, 2018

I was having this issue in my tests, which originally was:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

describe("App", () => {
	test("renders without crashing", () => {
		const div = document.createElement("div");
		ReactDOM.render(<App />, div);
	});
});

This would give the error discussed.

To solve it (at least for my tests), I had to add the div to the body, since the tooltip tries to query the document. This was the fix:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

describe("App", () => {
	test("renders without crashing", () => {
		const div = document.createElement("div");
		document.body.appendChild(div);
		ReactDOM.render(<App />, div);
	});
});

I hope this can bring any insights to what you are experiencing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reactstrap tooltip causes an error: The target 'TooltipExample ...
In constructor, tooltipOpen should be false . And then, in componentDidMount, switch tooltipOpen from false to true. This is code:
Read more >
Tooltips - reactstrap
reactstrap - easy to use React Bootstrap 4 components compatible with React 0.14.x and 15.
Read more >
4 Ways to Show Tooltips in React with react-tooltip, Material UI ...
In this example, we start by importing the ReactTooltip component. We use ReactTooltip to render the content of the tooltip. We specify the...
Read more >
Unknown Prop Warning - React
The unknown-prop warning will fire if you attempt to render a DOM element with a prop that is not recognized by React as...
Read more >
Position in React Tooltip component - Syncfusion
Tooltips can be attached to 12 static locations around the target. On initializing the Tooltip, you can set the position property with any...
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