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

chore: use custom event constructor instead of deprecated #8474

Conversation

tronicboy1
Copy link

@tronicboy1 tronicboy1 commented Apr 11, 2023

Problem

The custom_event function uses document.createEvent which is a deprecated method.

https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/initCustomEvent

Solution

use the constructor method, new CustomEvent(...), instead.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@vercel
Copy link

vercel bot commented Apr 11, 2023

@tronicboy1 is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@@ -61,6 +61,7 @@ global.navigator = window.navigator;
global.getComputedStyle = window.getComputedStyle;
global.requestAnimationFrame = null; // placeholder, filled in using set_raf
global.window = window;
global.CustomEvent = window.CustomEvent;
Copy link
Author

Choose a reason for hiding this comment

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

Needed to add the CustomEvent constructor to the global context for tests.

@dummdidumm
Copy link
Member

AFAIK this is kept that way to support old browsers which don't have this global yet. For Svelte 5 I would probably in favor of moving to the new event constructor, if it can be polyfilled.

@dummdidumm dummdidumm added this to the one day milestone Apr 11, 2023
@tronicboy1
Copy link
Author

I can understand that. Polyfilling is a can of worms I don’t think you want to open.

We could add an if clause for browsers that don’t have the global CustomEvent.

It’s been 3 years since the discussion for this implementation happened; now 99% of browsers support CustomEvent. It could be time to reconsider.

@Conduitry
Copy link
Member

It will be time to reconsider, when we are releasing a new major version of Svelte where we permit ourselves to make breaking changes. We can't just say "it's been several years, so we won't consider dropping support for these browsers a breaking change anymore".

@tronicboy1
Copy link
Author

@Conduitry

It will be time to reconsider, when we are releasing a new major version of Svelte where we permit ourselves to make breaking changes. We can't just say "it's been several years, so we won't consider dropping support for these browsers a breaking change anymore".

@Conduitry 100% agree with you, it would be a breaking change making it a major version change and I understand that now.

My apologies for coming across a bit rash, it's my first time attempting to contribute here 😅.

If there are other plans in place to fix some of the deprecated uses feel free to close this PR.

@tronicboy1 tronicboy1 changed the base branch from master to version-4 April 12, 2023 01:13
@benmccann benmccann deleted the branch sveltejs:master June 20, 2023 20:45
@benmccann benmccann closed this Jun 20, 2023
@benmccann benmccann reopened this Jun 20, 2023
@benmccann benmccann changed the base branch from version-4 to master June 20, 2023 20:52
dummdidumm added a commit that referenced this pull request Jun 21, 2023
dummdidumm added a commit that referenced this pull request Jun 21, 2023
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.

4 participants