Skip to content

Improve document context handling in ColumnSizing feature #5746

@parassantra

Description

@parassantra

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)

Screen.Recording.2024-09-15.at.21.40.25.mov

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

  • I agree to follow this project's Code of Conduct
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions