table icon indicating copy to clipboard operation
table copied to clipboard

Improve document context handling in ColumnSizing feature

Open parassantra opened this issue 1 year ago • 1 comments

TanStack Table version

v8.20.5

Framework/Library version

v18.2.0

Describe the bug and the steps to reproduce it

Description

The current implementation of the getResizeHandler function in the ColumnSizing feature doesn't properly handle the document context in all scenarios, particularly in environments where the global document object might not be available or when dealing with new windows and React.createPortal.

Proposed Change

typescript:packages/table-core/src/features/ColumnSizing.ts const contextDocument = contextDocument || (typeof document !== 'undefined' ? (((e as MouseEvent | TouchEvent).target as Element)?.ownerDocument ?? document) : null)

Expected Behaviour

  • The resize handler should work correctly in various environments, including iframes and server-side rendering scenarios.
  • It should prioritize the explicitly provided document context.
  • It should gracefully handle cases where the global document object is not available.

Current Behaviour

The current implementation may not work correctly in all scenarios, particularly when dealing with windows/iframes or in environments where the global document object is not available.

Steps to Reproduce

  1. Goto https://codesandbox.io/p/sandbox/github/parassantra/react-table-issue
  2. Resize table in parent window it works as expected
  3. Open Popout window also keep main window side by side and resize table.
  4. Mouse events will trigger infinite when mouse moved over parent window.

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://codesandbox.io/p/sandbox/github/parassantra/react-table-issue

Screenshots or Videos (Optional)

https://github.com/user-attachments/assets/97691e6e-fcff-4e65-8a26-7a956e7114f2

Do you intend to try to help solve this bug with your own PR?

Yes, I am also opening a PR that solves the problem along side this issue

Terms & Code of Conduct

  • [x] I agree to follow this project's Code of Conduct
  • [x] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

parassantra avatar Sep 16 '24 01:09 parassantra

@KevinVandy

parassantra avatar Sep 19 '24 17:09 parassantra