Reduce calls to .height() in slot.js#1
Reduce calls to .height() in slot.js#1scottmessinger wants to merge 17 commits intoconnected-sortablesfrom
Conversation
Line 134 caused a `Bad value context for arguments value`. I think babel transpiles the default argument in a way that doesn't help v8. The other idea is we're calling it with either 2 or 3 arguments which also might lead to the deopt.
For running in Ember Fastboot
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce forced reflow work during sortable interactions (notably by removing some .height() calls in slot.js) and includes related refactors around event timing and dependency/import updates.
Changes:
- Removes forced reflow calls in
addon/utils/slot.jswhen clearing styles and toggling transitions. - Coalesces
Gestureupdates into a singlerequestAnimationFramecallback per frame. - Updates dependencies/imports (adds
jquery, removesember-new-computed, introduces@ember/objectimports) and makestransitionenddetection safe whendocumentis unavailable.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Updates dependencies (babel + jQuery) and removes ember-new-computed. |
| addon/utils/transitionend.js | Adds a document-undefined guard for non-browser/SSR environments. |
| addon/utils/transition-duration.js | Switches to import $ from "jquery" and adds a null/undefined guard. |
| addon/utils/slot.js | Removes .height() calls after style updates (reducing forced reflow). |
| addon/utils/gesture.js | Throttles onUpdate calls to once per animation frame. |
| addon/utils/arrangement.js | Adjusts tree-walk path initialization and signature. |
| addon/mixins/sortable-node.js | Switches to jquery import and updates formatting/quoting. |
| addon/mixins/sortable-item.js | Switches computed/jQuery imports and adds a variety of guards/formatting changes. |
| addon/helpers/drag.js | Switches to jquery import and updates formatting/quoting. |
| addon/components/sortable-group.js | Replaces ember-new-computed import with @ember/object computed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { computed } from "@ember/object"; | ||
| import Ember from "ember"; | ||
| import $ from "jquery"; | ||
| const { Mixin, run } = Ember; |
There was a problem hiding this comment.
@ember/object module imports aren’t available in this addon’s current ember-try matrix (e.g., Ember 1.13 via bower). This import will fail to resolve under those scenarios; use Ember.computed (from the existing import Ember from "ember") or otherwise update the addon/tooling to ember-source + ember-modules throughout.
| import { computed } from "@ember/object"; | |
| import Ember from "ember"; | |
| import $ from "jquery"; | |
| const { Mixin, run } = Ember; | |
| import Ember from "ember"; | |
| import $ from "jquery"; | |
| const { Mixin, computed, run } = Ember; |
| @type Boolean | ||
| */ | ||
| isBusy: computed.or('isDragging', 'isDropping'), | ||
| isBusy: computed.or("isDragging", "isDropping"), |
There was a problem hiding this comment.
computed imported from @ember/object is a function and doesn’t have the computed macro helpers (like .or). As written, computed.or will be undefined and throw at runtime; use the appropriate macro (e.g., Ember.computed.or(...)) or import or from the correct module if you move fully to ember-modules.
| function getBorderSpacing(el) { | ||
| el = $(el); | ||
|
|
||
| let css = el.css('border-spacing'); // '0px 0px' | ||
| let [horizontal, vertical] = css.split(' '); | ||
| if (el === undefined || el === null) return 0; | ||
| let css = el.css("border-spacing"); // '0px 0px' | ||
| const [horizontal, initialVertical] = css.split(" "); | ||
| const vertical = initialVertical === undefined ? horizontal : initialVertical; |
There was a problem hiding this comment.
getBorderSpacing sometimes returns a number (0), but callers treat its return value as an object (.horizontal/.vertical). This will produce NaN widths/heights. Return a consistent { horizontal: 0, vertical: 0 } shape (and consider guarding when border-spacing CSS is missing/empty).
| import { computed } from '@ember/object'; | ||
| const { A, Component, get, set, run } = Ember; |
There was a problem hiding this comment.
@ember/object imports won’t resolve in the current ember-try scenarios that use bower Ember (e.g., 1.13). This will break those builds/tests unless the addon is migrated to ember-source + ember-modules. Also, the line has trailing whitespace which violates the repo’s .editorconfig (trim_trailing_whitespace = true).
| import { computed } from '@ember/object'; | |
| const { A, Component, get, set, run } = Ember; | |
| const { A, Component, computed, get, set, run } = Ember; |
| this.isInAnimationFrame = true; | ||
| window.requestAnimationFrame(() => { |
There was a problem hiding this comment.
Gesture accepts a configurable eventTarget, but this code hard-codes window.requestAnimationFrame, which makes it harder to test and can break if a non-window target is provided. Prefer the global requestAnimationFrame (as used elsewhere in this repo) or a requestAnimationFrame function sourced from eventTarget/injected for tests.
| this.isInAnimationFrame = true; | |
| window.requestAnimationFrame(() => { | |
| let requestAnimationFrameFn = this.eventTarget.requestAnimationFrame || requestAnimationFrame; | |
| this.isInAnimationFrame = true; | |
| requestAnimationFrameFn(() => { |
| "dependencies": { | ||
| "ember-cli-babel": "^5.1.5", | ||
| "ember-cli-babel": "^6.6.0", | ||
| "ember-cli-htmlbars": "^1.0.1", | ||
| "ember-new-computed": "^1.0.2" | ||
| "jquery": "^3.6.0" |
There was a problem hiding this comment.
The PR title focuses on reducing .height() calls in slot.js, but this change also upgrades ember-cli-babel, removes ember-new-computed, and adds jquery. Consider splitting dependency upgrades/migrations into a separate PR (or update the PR description) so the behavior change can be reviewed/tested independently.
58e354b to
c5dad12
Compare
No description provided.