Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: When using initialRect, the first rendered nodes do not observe ResizeObserver. #816

Closed

Conversation

MukaNakazato
Copy link

This fix changes the reference to instance.measureElement so that the ref callback is called again after instance._willUpdate() is called.

This PR resolves #815 .

…ResizeObserver

Fix to change the reference of instance.measureElement after instance._willUpdate() called so that the ref callback is called again.

Refs: TanStack#815
@@ -47,7 +47,8 @@ function useVirtualizerBase<
}, [])

useIsomorphicLayoutEffect(() => {
return instance._willUpdate()
instance._willUpdate()
instance.measureElement = instance.measureElement.bind(instance)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda feels like this is more core issue not react specific, hmm what about something like

As we should have elements in cache, we can observe elements when we set scroll element

Zrzut ekranu 2024-08-29 o 11 47 58

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, since this.cleanup() gets called in _willUpdate, this.elementsCache ends up being empty... It seems necessary to call cleanup when this.scrollElement changes, and it feels natural to clear the elementsCache within cleanup, but I can't figure out what the best solution is...

How about making it event-driven and only calling _measureElement after _willUpdate has been called?
I thought so, but it would be better if cleanup() also handled event listeners.

Hmm,I can’t come up with a good idea.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, this is bit tricky as when clearing scrollElement we can set it back, but with elementsCache we can't. Kinda feels maybe just stop observing with observer.disconnect() and observe back.

How about making it event-driven and only calling _measureElement after _willUpdate has been called?

When we observe back elements then _measureElement will be called from RO callback.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for now let's not clear the cache on clear and observe it back later #830

@piecyk piecyk closed this Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When using initialRect, the first rendered nodes do not observe ResizeObserver.
2 participants