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.

Setting `triggerTarget` with a ref doesn't actually set Tippy instance's option

See original GitHub issue

Bug description

I was trying to replicate the “Different Trigger Target” feature from tippy.js in React.

When I set the triggerTarget with the parent div’s ref, React re-renders the component and inserts the prop as expected, with the correct reference to the parent node. However, Tippy doesn’t update in this case. triggerTarget ends up being set in the underlying Tippy as null, even though the prop triggerTarget with the correct value is passed into it.

Reproduction

CodeSandbox

  • Notice that I logged the ref being set and that it is working as expected. It is initially null, then when the ref updates, it updates the prop.
  • However, the underlying Tippy instance’s triggerTarget option REMAINS as null.

My findings

It seems like the problem is here: https://github.com/atomiks/tippy.js-react/blob/846a3764e51d5bc315d433759639a606a7903f95/src/Tippy.js#L87-L96

This code doesn’t run on the first or second render for optimization reasons. However, because my ref is updating in the 2nd render, the options never get updated. Commenting out the return fixes this problem, which proves my hypothesis.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
atomikscommented, Aug 24, 2019

Just to explain things for clarity:

  • 1st render: the instance only just got created so no need to update anything yet
  • 2nd render: this is due to the creation effect (setMounted()) so that the component can re-render and use the portal content - it was assumed no options changed in this timeframe (except in this case you’ve listed which I didn’t consider where you can cause a re-render before setMounted() does it itself).
  • 3rd+ render: update any options dynamically while the instance is still alive. But, due to the above case you’ve listed, we can’t assume setMounted() will be the “last” render before we can update things.

So we’ll just need to change 3 to 2. Do you want to make a PR for this and a test case?

1reaction
jarstelfoxcommented, Aug 24, 2019

Does changing < 3 to < 2 work?

I believe so. It is rendering only twice here.

CC @nguyen-darianhuy

Read more comments on GitHub >

github_iconTop Results From Across the Web

Misc | Tippy.js
Consider the prop flipOnUpdate: true if you want the tippy to flip to best fit in view while the container is being scrolled....
Read more >
Popover on hover codepen - Caritas Castellaneta
For that, we will set html option as 'true' to allow HTML content inside popover when initializing at the initial phase. The :hover...
Read more >
tippyjs - Bountysource
I am running two Chrome extensions which both embed tippy.js. When both extensions are enabled, they seem to conflict with one another, whereas...
Read more >
React component for Tippy.js - Morioh
Default Tippy is very quick to use and setup and “just works” out of the box. Headless Tippy. Render your own tippy element...
Read more >
Multiple tippy.js instances on a single html element with ...
one which will be triggered on mouseenter event (the default one, created using default tippy constructor without using the trigger option at ...
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