Giter Site home page Giter Site logo

Comments (12)

atomiks avatar atomiks commented on June 25, 2024 1

I was considering adding it as a second argument (like a dependency array), but the types were a bit annoying and I didn't think it was a major enough issue to add in, but I might try to look into it again

from floating-ui.

atomiks avatar atomiks commented on June 25, 2024

Is the issue the same on 0.26.13?

from floating-ui.

LoganDark avatar LoganDark commented on June 25, 2024

yes it looks like it (put =0.26.13 in package.json and reinstalled, confirmed 0.26.13 is installed, restarted server and retested and same issue). my render function logs the values of these variables, THEN the callbacks are called and they print the old values, so it seems floating UI is keeping around a reference to an old callback from an old render instead of using the most recent one

from floating-ui.

atomiks avatar atomiks commented on June 25, 2024

Okay, .14 had a somewhat major refactor that I was curious was causing the problem. But if it's happening in the old version I'm skeptical it's this library's issue. useEffectEvent (the function you posted) is used internally where necessary, and the lint rules are enabled to ensure useCallbacks have fresh values during rendering.

Without a reproduction it's hard to debug - if you can, try to find some time to make a new CodeSandbox that reproduces the issue!

from floating-ui.

LoganDark avatar LoganDark commented on June 25, 2024

I have time, it's just all of codesandbox's buttons are disabled for some reason?
image
like, it literally just won't let me

from floating-ui.

atomiks avatar atomiks commented on June 25, 2024

CodeSandbox's recent changes have been weird, try to create a brand new Sandbox entirely

from floating-ui.

LoganDark avatar LoganDark commented on June 25, 2024

image
how?

from floating-ui.

LoganDark avatar LoganDark commented on June 25, 2024

oh, it wants me to sign in, let me try that

from floating-ui.

LoganDark avatar LoganDark commented on June 25, 2024

here you go

to reproduce:

  • click the "add 10" button
  • the tooltip does nothing
  • click remount
  • woah

from floating-ui.

atomiks avatar atomiks commented on June 25, 2024

So this is an edge case where state values aren't fresh inside functions of middleware. Refs can be fresh, but they're also not reactive.

To keep using state, which is both reactive and fresh, you need to inform Floating UI about the value changing:

const sizeMiddleware = size({
  apply({ elements }) {
    elements.floating.style.height = `${state}px`;
  },
});

const reactiveSize = {
  ...sizeMiddleware,
  options: {
    ...sizeMiddleware.options,
    deps: [state],
  }
};

useFloating({
  middleware: [reactiveSize]
})

https://codesandbox.io/p/sandbox/floating-ui-react-dom-template-forked-vmtmz4?file=%2Fsrc%2FApp.js%3A22%2C1

Docs: https://floating-ui.com/docs/useFloating#option-reactivity

from floating-ui.

LoganDark avatar LoganDark commented on June 25, 2024

ok, thank you! that looks exactly like what I am running into

from floating-ui.

LoganDark avatar LoganDark commented on June 25, 2024

yep I can confirm even just

 			size({
 				apply({availableHeight, elements}) {
 					console.log('extraLeftPadding = %o, extraRightPadding = %o', extraLeftPadding, extraRightPadding)
 					elements.floating.style.width = `${elements.reference.getBoundingClientRect().width - leftPadding - rightPadding + 2 * unit}px`
 					elements.floating.style.maxHeight = `${Math.max(availableHeight, 20 * unit)}px` // 4 items
 				},
+				deps: [extraLeftPadding, extraRightPadding, unit]
 			}),

immediately fixes the issue

wonder if you should make this deps an official optional field so that typescript stops complaining at me

it'd probably be SUPER helpful for discoverability as well

from floating-ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.