Skip to content

Reduce calls to .height() in slot.js#1

Open
scottmessinger wants to merge 17 commits intoconnected-sortablesfrom
reduce-relayouts
Open

Reduce calls to .height() in slot.js#1
scottmessinger wants to merge 17 commits intoconnected-sortablesfrom
reduce-relayouts

Conversation

@scottmessinger
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 1, 2026 19:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.js when clearing styles and toggling transitions.
  • Coalesces Gesture updates into a single requestAnimationFrame callback per frame.
  • Updates dependencies/imports (adds jquery, removes ember-new-computed, introduces @ember/object imports) and makes transitionend detection safe when document is 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.

Comment thread addon/mixins/sortable-item.js Outdated
Comment on lines +1 to +4
import { computed } from "@ember/object";
import Ember from "ember";
import $ from "jquery";
const { Mixin, run } = Ember;
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

@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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment thread addon/mixins/sortable-item.js Outdated
@type Boolean
*/
isBusy: computed.or('isDragging', 'isDropping'),
isBusy: computed.or("isDragging", "isDropping"),
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 568 to +573
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;
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
Comment on lines +3 to 4
import { computed } from '@ember/object';
const { A, Component, get, set, run } = Ember;
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

@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).

Suggested change
import { computed } from '@ember/object';
const { A, Component, get, set, run } = Ember;
const { A, Component, computed, get, set, run } = Ember;

Copilot uses AI. Check for mistakes.
Comment thread addon/utils/gesture.js
Comment on lines +199 to +200
this.isInAnimationFrame = true;
window.requestAnimationFrame(() => {
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
this.isInAnimationFrame = true;
window.requestAnimationFrame(() => {
let requestAnimationFrameFn = this.eventTarget.requestAnimationFrame || requestAnimationFrame;
this.isInAnimationFrame = true;
requestAnimationFrameFn(() => {

Copilot uses AI. Check for mistakes.
Comment thread package.json Outdated
Comment on lines +45 to +48
"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"
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

3 participants