A platform for community discussion. Free, open, simple.
DEV: Resolve memory leaks in qunit tests (#43400)
David Taylordadd7f3e508c
diff --git a/frontend/discourse/app/instance-initializers/narrow-desktop.js b/frontend/discourse/app/instance-initializers/narrow-desktop.jsindex c5474e6b656..7b07de50500 100644--- a/frontend/discourse/app/instance-initializers/narrow-desktop.js+++ b/frontend/discourse/app/instance-initializers/narrow-desktop.js@@ -1,3 +1,4 @@+import { registerDestructor } from "@ember/destroyable";import NarrowDesktop from "discourse/lib/narrow-desktop";export default {@@ -12,12 +13,17 @@ export default {// even when the user zooms the page.const mediaQuery = window.matchMedia("(min-width: 48rem)");- mediaQuery.addEventListener("change", () => {+ const onChange = () => {if (owner.isDestroyed) {return;}NarrowDesktop.update(owner, !mediaQuery.matches);- });+ };++ mediaQuery.addEventListener("change", onChange);+ registerDestructor(owner, () =>+ mediaQuery.removeEventListener("change", onChange)+ );},};diff --git a/frontend/discourse/app/lib/textarea-text-manipulation.ts b/frontend/discourse/app/lib/textarea-text-manipulation.tsindex bbe0c5ae2e3..d52ae4ef7d8 100644--- a/frontend/discourse/app/lib/textarea-text-manipulation.ts+++ b/frontend/discourse/app/lib/textarea-text-manipulation.ts@@ -1,3 +1,4 @@+import { destroy } from "@ember/destroyable";import { type default as Owner, getOwner, setOwner } from "@ember/owner";import { trackedObject } from "@ember/reactive/collections";import { next, schedule } from "@ember/runloop";@@ -114,6 +115,8 @@ export default class TextareaTextManipulation implements TextManipulation {@service declare capabilities: CapabilitiesService;+ autocompletes: object[] = [];+allowPreview = true;eventPrefix: string;@@ -1004,13 +1007,21 @@ export default class TextareaTextManipulation implements TextManipulation {}}- autocomplete(options: AutocompleteOptions): unknown {- return dAutocomplete.setupAutocomplete(+ autocomplete(options: AutocompleteOptions | "destroy"): unknown {+ if (options === "destroy") {+ this.autocompletes.forEach((modifier) => destroy(modifier));+ this.autocompletes = [];+ return;+ }++ const modifier = dAutocomplete.setupAutocomplete(getOwner(this),this.textarea,this.autocompleteHandler,options);+ this.autocompletes.push(modifier);+ return modifier;}#applyWholeLineSurround(diff --git a/frontend/discourse/app/lib/uppy/uppy-upload.js b/frontend/discourse/app/lib/uppy/uppy-upload.jsindex 7ba57ee9ce5..67538ca69d0 100644--- a/frontend/discourse/app/lib/uppy/uppy-upload.js+++ b/frontend/discourse/app/lib/uppy/uppy-upload.js@@ -146,7 +146,7 @@ export default class UppyUpload {`upload-mixin:${this.config.id}:cancel-upload`,this.cancelSingleUpload);- this.uppyWrapper.uppyInstance.close?.();+ this.uppyWrapper.uppyInstance.destroy();}}diff --git a/frontend/discourse/app/models/composer.js b/frontend/discourse/app/models/composer.jsindex 3cf2d1d1b8f..8bb7e1a8a2b 100644--- a/frontend/discourse/app/models/composer.js+++ b/frontend/discourse/app/models/composer.js@@ -1,4 +1,3 @@-/* eslint-disable ember/no-observers */import { tracked } from "@glimmer/tracking";import EmberObject, { computed, set } from "@ember/object";import { dependentKeyCompat } from "@ember/object/compat";@@ -6,7 +5,7 @@ import { next, throttle } from "@ember/runloop";import { service } from "@ember/service";import { isHTMLSafe } from "@ember/template";import { isEmpty } from "@ember/utils";-import { observes, on } from "@ember-decorators/object";+import { on } from "@ember-decorators/object";import { Promise } from "rsvp";import { extractError, throwAjaxError } from "discourse/lib/ajax-error";import { tinyAvatar } from "discourse/lib/avatar-utils";@@ -234,6 +233,36 @@ export default class Composer extends RestModel {@tracked _user;+ @tracked _composeState;++ @tracked _archetypeId;++ @dependentKeyCompat+ get composeState() {+ return this._composeState;+ }++ set composeState(value) {+ if (value === this._composeState) {+ return;+ }+ this._composeState = value;+ this.composeStateChanged();+ }++ @dependentKeyCompat+ get archetypeId() {+ return this._archetypeId;+ }++ set archetypeId(value) {+ if (value === this._archetypeId) {+ return;+ }+ this._archetypeId = value;+ this.set("metaData", EmberObject.create());+ }+@dependentKeyCompatget user() {return applyValueTransformer("composer-user", this._user, {@@ -856,7 +885,6 @@ export default class Composer extends RestModel {return true;}- @observes("composeState")composeStateChanged() {const oldOpen = this.composerOpened;const elem = document.documentElement;@@ -880,11 +908,6 @@ export default class Composer extends RestModel {}}- @observes("archetype")- archetypeChanged() {- return this.set("metaData", EmberObject.create());- }-// called whenever the user types to update the typing timetyping() {throttle(diff --git a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.ts b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.tsindex 0582430b9c5..5f84808b646 100644--- a/frontend/discourse/app/static/prosemirror/lib/text-manipulation.ts+++ b/frontend/discourse/app/static/prosemirror/lib/text-manipulation.ts@@ -1,3 +1,4 @@+import { destroy } from "@ember/destroyable";import { type default as Owner, getOwner, setOwner } from "@ember/owner";import { trackedObject } from "@ember/reactive/collections";import { next } from "@ember/runloop";@@ -90,6 +91,8 @@ function isPlainTextFragment(fragment: Fragment, schema: Schema): boolean {}export default class ProsemirrorTextManipulation implements TextManipulation {+ autocompletes: object[] = [];+allowPreview = false;schema: Schema;@@ -181,13 +184,21 @@ export default class ProsemirrorTextManipulation implements TextManipulation {});}- autocomplete(options: AutocompleteOptions): unknown {- return dAutocomplete.setupAutocomplete(+ autocomplete(options: AutocompleteOptions | "destroy"): unknown {+ if (options === "destroy") {+ this.autocompletes.forEach((modifier) => destroy(modifier));+ this.autocompletes = [];+ return;+ }++ const modifier = dAutocomplete.setupAutocomplete(getOwner(this),this.view.dom,this.autocompleteHandler,options);+ this.autocompletes.push(modifier);+ return modifier;}applySurroundSelection(diff --git a/frontend/discourse/app/ui-kit/modifiers/d-autocomplete.js b/frontend/discourse/app/ui-kit/modifiers/d-autocomplete.jsindex b6bd236dbd6..93a0ebf1809 100644--- a/frontend/discourse/app/ui-kit/modifiers/d-autocomplete.js+++ b/frontend/discourse/app/ui-kit/modifiers/d-autocomplete.js@@ -1,5 +1,8 @@import { tracked } from "@glimmer/tracking";-import { registerDestructor } from "@ember/destroyable";+import {+ associateDestroyableChild,+ registerDestructor,+} from "@ember/destroyable";import { action } from "@ember/object";import { cancel } from "@ember/runloop";import { service } from "@ember/service";@@ -54,6 +57,7 @@ export default class DAutocompleteModifier extends Modifier {named: {},positional: [],});+ associateDestroyableChild(owner, modifier);const modifierOptions = {...options,diff --git a/frontend/discourse/dialog-holder/components/dialog-holder.gjs b/frontend/discourse/dialog-holder/components/dialog-holder.gjsindex 792cbe3d7fb..0e11e84ec4c 100644--- a/frontend/discourse/dialog-holder/components/dialog-holder.gjs+++ b/frontend/discourse/dialog-holder/components/dialog-holder.gjs@@ -19,7 +19,7 @@ export default class DialogHolder extends Component {this.dialog.hide();});- () => {+ return () => {dialogInstance.hide();dialogInstance.destroy();};diff --git a/frontend/discourse/tests/setup-tests.js b/frontend/discourse/tests/setup-tests.jsindex 7f5b0dadfd9..0800b6bec6a 100644--- a/frontend/discourse/tests/setup-tests.js+++ b/frontend/discourse/tests/setup-tests.js@@ -335,6 +335,11 @@ export default async function setupTests(config) {app.destroy();});+ // The inspector shim's global list would otherwise pin the destroyed app's registry.+ globalThis.emberInspectorApps = globalThis.emberInspectorApps?.filter(+ (entry) => entry.app !== app+ );+resetPretender();clearPresenceState();diff --git a/patches/@[email protected] b/patches/@[email protected]new file mode 100644index 00000000000..8bc7454998e--- /dev/null+++ b/patches/@[email protected]@@ -0,0 +1,25 @@+diff --git a/dist/index.js b/dist/index.js+index 566dc18edcce674cb20c1c07f60ff9d4f783eb35..8fc5700da577050452329140a01754fa3347b900 100644+--- a/dist/index.js++++ b/dist/index.js+@@ -9,7 +9,7 @@ import '@ember/debug';+ import '@warp-drive/utilities/string';+ import { macroCondition, getGlobalConfig } from '@embroider/macros';+ import '@warp-drive/core/store/-private';+-import "./errors-Cz5KrzBk.js";++import { L as LEGACY_SUPPORT } from "./errors-Cz5KrzBk.js";+ import "./schema-provider-DJCV_6AF.js";+ import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-D6diaM34.js";+ import { registerDerivations as registerDerivations$1, DelegatingSchemaService } from './model/migration-support.js';+@@ -109,6 +109,11 @@ function useLegacyStore(options, StoreKlass = Store) {+ if (this.schema.isDelegated(key)) {+ return teardownRecord.call(this, record);+ }++ const support = LEGACY_SUPPORT.get(key);++ if (support) {++ support.destroy();++ LEGACY_SUPPORT.delete(key);++ }+ return teardownRecord$1(record);+ }+ modelFor(type) {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 75e13f9348b..b6ea532869a 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -13,6 +13,9 @@ patchedDependencies:'@ember-compat/[email protected]':hash: febdd1f1d24565f6f3be7747fd89cbc86a4476e2836e383610c6bc430436a842path: patches/@[email protected]+ '@warp-drive/[email protected]':+ hash: de74ff6c540d75d173dcb41244cb6c4f6c86dabdb41908170a9d1c0e47ee099f+ path: patches/@[email protected]hash: 387f93bad78f3a98b20dc742f4f0b7a165c7e6ebc65cc60356748346c0725c7fpath: patches/[email protected]@@ -314,7 +317,7 @@ importers:version: 5.9.0-alpha.15(@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected]))'@warp-drive/legacy':specifier: 5.9.0-alpha.15- version: 5.9.0-alpha.15(@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected]))(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])))+ version: 5.9.0-alpha.15(patch_hash=de74ff6c540d75d173dcb41244cb6c4f6c86dabdb41908170a9d1c0e47ee099f)(@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected]))(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])))'@warp-drive/utilities':specifier: 5.9.0-alpha.15version: 5.9.0-alpha.15(@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected]))@@ -11255,7 +11258,7 @@ snapshots:- '@glint/template'- supports-color- '@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected]))(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])))':+ '@warp-drive/[email protected](patch_hash=de74ff6c540d75d173dcb41244cb6c4f6c86dabdb41908170a9d1c0e47ee099f)(@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected]))(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])(@warp-drive/[email protected](@babel/[email protected])(@glint/[email protected])))':dependencies:'@embroider/macros': 1.20.6(@babel/[email protected])(@glint/[email protected])'@warp-drive/core': 5.9.0-alpha.15(@babel/[email protected])(@glint/[email protected])diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 887f21ef884..bbb20fcc78f 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -70,6 +70,8 @@ patchedDependencies:"[email protected]": "patches/[email protected]""[email protected]": "patches/[email protected]""@ember-compat/[email protected]": "patches/@[email protected]"+ # https://github.com/warp-drive-data/warp-drive/pull/11037+ "@warp-drive/[email protected]": "patches/@[email protected]""[email protected]": "patches/[email protected]""[email protected]": "patches/[email protected]""ember-buffered-proxy": "patches/ember-buffered-proxy.patch"