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

PRO-6477 undhandled promise errors #4700

Merged
merged 17 commits into from
Sep 3, 2024
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

### Fixes

* Registering duplicate icon is no longer breaking the build.
* Fix widget focus state so that the in-context Add Content menu stays visible during animation
* Fix UI of areas in schemas so that their context menus are layered overtop sibling schema fields UI
* Fix unhandled promise rejections and guard against potential memory leaks, remove 3rd party `debounce-async` dependency
* Adds an option to center the context menu arrow on the button icon. Sets this new option on some context menus in the admin UI.

## 4.6.1 (2024-08-26)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</template>

<script>
import { debounce } from 'Modules/@apostrophecms/ui/utils';
import debounce from 'lodash/debounce';
import { Cropper } from 'vue-advanced-cropper';
import 'vue-advanced-cropper/dist/style.css';

Expand Down Expand Up @@ -129,6 +129,10 @@ export default {
};
},
beforeUnmount() {
this.onScreenResizeDebounced.cancel();
this.handleCropperChangeDebounced.cancel();
this.setCropperCoordinatesDebounced.cancel();
this.updateFocalPointCoordinatesDebounced.cancel();
this.$refs.focalPoint.removeEventListener('mousedown', this.onFocalPointMouseDown);
window.removeEventListener('resize', this.onScreenResizeDebounced);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@
</template>

<script>
import { debounce } from 'Modules/@apostrophecms/ui/utils';
import { createId } from '@paralleldrive/cuid2';
import { debounceAsync } from 'Modules/@apostrophecms/ui/utils';
import AposModifiedMixin from 'Modules/@apostrophecms/ui/mixins/AposModifiedMixin';
import AposDocsManagerMixin from 'Modules/@apostrophecms/modal/mixins/AposDocsManagerMixin';
import { createId } from '@paralleldrive/cuid2';

const DEBOUNCE_TIMEOUT = 500;

Expand Down Expand Up @@ -166,7 +166,9 @@ export default {
emoji: '🖼'
},
cancelDescription: 'apostrophe:discardImageChangesPrompt',
debouncedGetMedia: debounce(this.getMedia, DEBOUNCE_TIMEOUT),
debouncedGetMedia: debounceAsync(this.getMedia, DEBOUNCE_TIMEOUT, {
onSuccess: this.appendMedia
}),
loadObserver: new IntersectionObserver(
this.handleIntersect,
{
Expand Down Expand Up @@ -243,6 +245,7 @@ export default {
return this.totalPages > 1 && this.currentPage === this.totalPages;
}
},

watch: {
async checked (newVal, oldVal) {
this.lastSelected = newVal.at(-1);
Expand Down Expand Up @@ -270,21 +273,26 @@ export default {
}
}
},

created() {
this.setDefaultFilters();
},

async mounted() {
this.modal.active = true;
await this.getMedia({ tags: true });
this.isFirstLoading = false;

// Do these before any async work or they might get added after they are "removed"
apos.bus.$on('content-changed', this.onContentChanged);
apos.bus.$on('command-menu-manager-close', this.confirmAndCancel);
await this.debouncedGetMedia.skipDelay({ tags: true });
this.isFirstLoading = false;
},
unmounted() {

beforeUnmount() {
this.debouncedGetMedia.cancel();
myovchev marked this conversation as resolved.
Show resolved Hide resolved
apos.bus.$off('content-changed', this.onContentChanged);
apos.bus.$off('command-menu-manager-close', this.confirmAndCancel);
},

methods: {
setDefaultFilters() {
this.moduleOptions.filters.forEach(filter => {
Expand All @@ -296,7 +304,8 @@ export default {
editorModified (val) {
this.modified = val;
},
async getMedia (options = {}) {
async getMedia(options = {}) {
const result = {};
const qs = {
...this.filterValues,
page: this.currentPage,
Expand Down Expand Up @@ -344,23 +353,35 @@ export default {
draft: true
}
));
this.tagList = apiResponse.choices._tags;
result.tagList = apiResponse.choices._tags;
} else {
this.tagList = apiResponse.choices ? apiResponse.choices._tags : [];
result.tagList = apiResponse.choices ? apiResponse.choices._tags : [];
}
}

this.currentPage = apiResponse.currentPage;
this.totalPages = apiResponse.pages;
result.currentPage = apiResponse.currentPage;
result.totalPages = apiResponse.pages;
result.items = [];
for (const image of apiResponse.results) {
this.items.push(image);
result.items.push(image);
}
return result;
},
async appendMedia({
tagList, currentPage, totalPages, items
}) {
this.tagList = tagList;
this.currentPage = currentPage;
this.totalPages = totalPages;
for (const item of items) {
this.items.push(item);
}
},
async refetchMedia(opts) {
this.isLoading = true;
this.currentPage = 1;
this.items = [];
await this.getMedia(opts);
await this.debouncedGetMedia.skipDelay(opts);
this.isLoading = false;
this.modified = false;
this.updateEditing(null);
Expand All @@ -376,11 +397,10 @@ export default {
dimensions
});
},
async completeUploading (imgIds) {
async completeUploading(imgIds) {
this.currentPage = 1;
this.items = [];
await this.getMedia();

await this.debouncedGetMedia.skipDelay();
if (Array.isArray(imgIds) && imgIds.length && this.items.length === 0) {
const [ widgetOptions = {} ] = apos.area.widgetOptions;
const [ width, height ] = widgetOptions.minSize || [];
Expand Down Expand Up @@ -551,7 +571,7 @@ export default {
this.loadRef.scrollIntoView({
behavior: 'smooth'
});
await this.getMedia();
await this.debouncedGetMedia.skipDelay();
this.isScrollLoading = false;
}
}
Expand Down
Loading
Loading