Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: addonAnimationFrame lifecycle function#14594

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Rich-Harris wants to merge6 commits intomain
base:main
Choose a base branch
Loading
fromonframe
Draft

Conversation

Rich-Harris
Copy link
Member

Just an idle thought I had while washing the dishes: should we have anonFrame function? It would mean for example thatthis demo could be writtenlike this:

$effect(()=>{constcontext=canvas.getContext('2d');onFrame(()=>{paint(context,Date.now());});});

Alternatively we might want to have some sort of reactive time primitive (other thanSvelteDate) so that it could be used in deriveds too. Either way not wedded to it, just an idle thought that I thought was worth a PR

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 withfeat:,fix:,chore:, ordocs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code withinpackages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests withpnpm test and lint the project withpnpm lint

Ocean-OS, damianpumar, and xmlking reacted with thumbs up emojigka reacted with heart emoji
@changeset-botchangeset-bot
Copy link

changeset-botbot commentedDec 6, 2024
edited
Loading

🦋 Changeset detected

Latest commit:605a1f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
svelteMinor

Not sure what this means?Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris
Copy link
MemberAuthor

preview:https://svelte-dev-git-preview-svelte-14594-svelte.vercel.app/

this is an automated message

@github-actionsGitHub Actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@14594

1 similar comment
@github-actionsGitHub Actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@14594

@dummdidumm
Copy link
Member

While it's nice, this does feel more of a thing for a utility or animation library. I wouldn't call it a lifecycle function at least and expose it throughsvelte/reactivity instead.

lanye74 and ryoppippi reacted with thumbs up emoji

@ottomated
Copy link
Contributor

Adjacent to#12441

@trueadm
Copy link
Contributor

trueadm commentedDec 12, 2024
edited
Loading

Adjacent to#12441

I'm not sure it is at all. You definitely don't want to be updating the UI withDate.now() every frame, that's going to put a lot of pressure on the runtime for no real benefit. I'd imagine you'd only want to update the time in relation to your UI requirements, such as every second or minute. This is very much a user-space problem rather than a problem that Svelte should even attempt to solve.

@Rich-HarrisRich-Harris changed the titlefeat: addonFrame lifecycle functionfeat: addonAnimationFrame lifecycle functionApr 12, 2025
@svelte-docs-bot
Copy link

@Rich-Harris
Copy link
MemberAuthor

Renamed toonAnimationFrame. I toyed with putting it insvelte/reactivity orsvelte/motion but neither felt right — I think you can make the case that itis a lifecycle function, and it definitely feels more natural to me to have it alongsideonMount than elsewhere

@dummdidumm
Copy link
Member

FWIW I still think this is not worth adding as it's so easy to replicate in user land - so if this is about cleaning the PR queue I'd rather close it.

@Rich-Harris
Copy link
MemberAuthor

It'seasy but annoying — you have to understand whether it's 'safe' to run the logic inside arequestAnimationFrame callback the first time or if it'll result in flicker unless you call it directly inside the effect, in which case you might need to faff about withuntrack unless you're usingonMount (you don't need to, because itis safe, but that means you have to callrequestAnimationFrame twice — once inside the callback, once to kick it off). And of course it's a lot more verbose — this...

$effect(()=>{letframe=requestAnimationFrame(functionnext(){frame=requestAnimationFrame(next);do_stuff();});return()=>{cancelAnimationFrame(frame);};});

...versus this:

import{onAnimationFrame}from'svelte';onAnimationFrame(()=>{do_stuff();});

The intent-to-noise ratio is much higher in the second case. It's something I've wanted often enough that I do think its presence is justified, it's not just about cleaning the PR queue.

huntabyte reacted with thumbs up emojigka reacted with heart emoji

@dummdidumm
Copy link
Member

I'm not saying it doesn't have any value, but not that it deserves to be in the same place as things like "real" life cycle hooks or other important stuff under thesvelte import space. It feels like something that can be put into a 3rd party lib likeruned

@TGlide
Copy link
Member

I'm not saying it doesn't have any value, but not that it deserves to be in the same place as things like "real" life cycle hooks or other important stuff under thesvelte import space. It feels like something that can be put into a 3rd party lib likeruned

We have something similar in runed :)https://www.runed.dev/docs/utilities/animation-frames

@Rich-HarrisRich-Harris marked this pull request as draftJuly 16, 2025 21:53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@trueadmtrueadmtrueadm left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@Rich-Harris@dummdidumm@ottomated@trueadm@TGlide

[8]ページ先頭

©2009-2025 Movatter.jp