From 2dead17c793537469c8c93bb80bc4c764dfaefe8 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Wed, 21 Jun 2023 09:58:21 +0200 Subject: [PATCH] breaking: use `CustomEvent` constructor instead of deprecated `createEvent` method closes #8474 --- .changeset/odd-wasps-smoke.md | 5 +++++ documentation/docs/05-misc/04-v4-migration-guide.md | 1 + packages/svelte/src/runtime/internal/dom.js | 7 +------ 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 .changeset/odd-wasps-smoke.md diff --git a/.changeset/odd-wasps-smoke.md b/.changeset/odd-wasps-smoke.md new file mode 100644 index 000000000000..9a0effc88a36 --- /dev/null +++ b/.changeset/odd-wasps-smoke.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +breaking: use `CustomEvent` constructor instead of deprecated `createEvent` method diff --git a/documentation/docs/05-misc/04-v4-migration-guide.md b/documentation/docs/05-misc/04-v4-migration-guide.md index 41d06e65008a..5a0dc18b5a61 100644 --- a/documentation/docs/05-misc/04-v4-migration-guide.md +++ b/documentation/docs/05-misc/04-v4-migration-guide.md @@ -151,6 +151,7 @@ The order in which preprocessors are applied has changed. Now, preprocessors are - the `inert` attribute is now applied to outroing elements to make them invisible to assistive technology and prevent interaction. ([#8628](https://github.com/sveltejs/svelte/pull/8628)) - the runtime now uses `classList.toggle(name, boolean)` which may not work in very old browsers. Consider using a [polyfill](https://github.com/eligrey/classList.js) if you need to support these browsers. ([#8629](https://github.com/sveltejs/svelte/issues/8629)) +- the runtime now uses the `CustomElement` constructor which may not work in very old browsers. Consider using a [polyfill](https://github.com/theftprevention/event-constructor-polyfill/tree/master) if you need to support these browsers. ([#8775](https://github.com/sveltejs/svelte/pull/8775)) - people implementing their own stores from scratch using the `StartStopNotifier` interface (which is passed to the create function of `writable` etc) from `svelte/store` now need to pass an update function in addition to the set function. This has no effect on people using stores or creating stores using the existing Svelte stores. ([#6750](https://github.com/sveltejs/svelte/issues/6750)) - `derived` will now throw an error on falsy values instead of stores passed to it. ([#7947](https://github.com/sveltejs/svelte/issues/7947)) - type definitions for `svelte/internal` were removed to further discourage usage of those internal methods which are not public API. Most of these will likely change for Svelte 5 diff --git a/packages/svelte/src/runtime/internal/dom.js b/packages/svelte/src/runtime/internal/dom.js index f456e9abd765..e1969c5514b7 100644 --- a/packages/svelte/src/runtime/internal/dom.js +++ b/packages/svelte/src/runtime/internal/dom.js @@ -1005,12 +1005,7 @@ export function toggle_class(element, name, toggle) { * @returns {CustomEvent} */ export function custom_event(type, detail, { bubbles = false, cancelable = false } = {}) { - /** - * @type {CustomEvent} - */ - const e = document.createEvent('CustomEvent'); - e.initCustomEvent(type, bubbles, cancelable, detail); - return e; + return new CustomEvent(type, { detail, bubbles, cancelable }); } /**