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

WindowScroller initial width and height are undefined #1857

Closed
learningfe opened this issue Nov 27, 2024 · 0 comments
Closed

WindowScroller initial width and height are undefined #1857

learningfe opened this issue Nov 27, 2024 · 0 comments
Labels

Comments

@learningfe
Copy link

Bug Report

When I use the WindowScroller HOC, if you pass the scrollElement property, WindowScroller will get the wrong initial state (width and height), and the child component (like Collection) will receive the undefined props:

image
<WindowScroller scrollElement={scrollElement}>
  {({ width, height }) => console.log(width, height)}  //  you will get two undefined at first render
</WindowScroller>

The problem seems to be caused by the spread syntax, it can not copy the DOMRect type data:

...getDimensions(this.props.scrollElement, this.props),

console.log({ ...document.body.getBoundingClientRect())
// output is {}

The spread syntax will be transformed to this:

_defineProperty(_assertThisInitialized(_this), "state", _objectSpread({}, getDimensions(_this.props.scrollElement, _this.props), {
  isScrolling: false,
  scrollLeft: 0,
  scrollTop: 0
}));

This is the implementation of _objectSpread on my development environment, it only assigns the own property of parameters:

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@learningfe learningfe changed the title WindowScroller initial state WindowScroller initial width and height is undefined Nov 27, 2024
@learningfe learningfe changed the title WindowScroller initial width and height is undefined WindowScroller initial width and height are undefined Nov 27, 2024
@github-actions github-actions bot added the Stale label Dec 26, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant