Comments (12)
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.
Is the issue the same on 0.26.13
?
from floating-ui.
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.
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 useCallback
s 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.
I have time, it's just all of codesandbox's buttons are disabled for some reason?
like, it literally just won't let me
from floating-ui.
CodeSandbox's recent changes have been weird, try to create a brand new Sandbox entirely
from floating-ui.
from floating-ui.
oh, it wants me to sign in, let me try that
from floating-ui.
to reproduce:
- click the "add 10" button
- the tooltip does nothing
- click remount
- woah
from floating-ui.
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]
})
Docs: https://floating-ui.com/docs/useFloating#option-reactivity
from floating-ui.
ok, thank you! that looks exactly like what I am running into
from floating-ui.
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)
- UseInteractionsReturn is missing HOT 1
- Regression in @floating-ui/[email protected] and return focus HOT 2
- Modal with FloatingFocusManager and no autoFocus scrolling to top of page HOT 6
- useListNavigation moves focus into list unexpectedly when an item is dynamically removed from the list HOT 8
- [Core] `size` middleware not correctly clipping floating element width/height
- Problem with flip/shift when floating element is zoomed HOT 1
- FloatingDelayGroup - This Suspense boundary received an update before it finished hydrating HOT 1
- When the focused element of a `FloatingFocusManager` is removed from the dom focus escapes to the `body` HOT 3
- [React-native] Android does not adjust based on reference's y-cordinate HOT 2
- Update dependency of floating-ui/react-dom HOT 1
- Fixed element as child of `dialog` element wrapped by element with `container-type` is positioned incorrectly HOT 3
- Unnecessary autoUpdate when content changes through animation HOT 1
- @floating-ui/react: Using `restMs` option for `useHover` causes SyntheticEvent warning on React 16
- can't work with antd modal HOT 1
- React Select component example not working in native dialog HOT 4
- Missing fade out animation when FloatingArrow used with FloatingDelayGroup HOT 1
- incorrect positioning with fixed ancestors + shadow DOM + parent overflow: hidden + `shift`/`autoPlacement` modifiers HOT 1
- onClick/onHover doesn't trigger for parent most dropdown HOT 2
- Hide Middleware Not Hiding Panel When Reference Element Off-Screen (Shadow DOM Components) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from floating-ui.