Skip to content

feat: add onAnimationFrame 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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename to onAnimationFrame
  • Loading branch information
Rich-Harris committed Apr 12, 2025
commit fbf247d26801977516dbc1fa1803d4e57ad2b87e
6 changes: 3 additions & 3 deletions packages/svelte/src/index-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ export function afterUpdate(fn) {
}

/**
* The `onFrame` function schedules a callback to run on `requestAnimationFrame`. It must be called inside an effect (e.g. during component initialisation).
* The `onAnimationFrame` function schedules a callback to run on `requestAnimationFrame`. It must be called inside an effect (e.g. during component initialisation).
*
* `onFrame` does not run inside [server-side components](https://svelte.dev/docs/svelte/svelte-server#render).
* `onAnimationFrame` does not run inside [server-side components](https://svelte.dev/docs/svelte/svelte-server#render).
*
* @template T
* @param {() => NotFunction<T> | Promise<NotFunction<T>> | (() => any)} fn
* @returns {void}
*/
export function onFrame(fn) {
export function onAnimationFrame(fn) {
onMount(() => {
let frame = -1;

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/index-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function onDestroy(fn) {
export {
noop as beforeUpdate,
noop as afterUpdate,
noop as onFrame,
noop as onAnimationFrame,
noop as onMount,
noop as flushSync,
run as untrack
Expand Down
6 changes: 3 additions & 3 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,12 @@ declare module 'svelte' {
* */
export function afterUpdate(fn: () => void): void;
/**
* The `onFrame` function schedules a callback to run on `requestAnimationFrame`. It must be called inside an effect (e.g. during component initialisation).
* The `onAnimationFrame` function schedules a callback to run on `requestAnimationFrame`. It must be called inside an effect (e.g. during component initialisation).
*
* `onFrame` does not run inside [server-side components](https://svelte.dev/docs/svelte/svelte-server#render).
* `onAnimationFrame` does not run inside [server-side components](https://svelte.dev/docs/svelte/svelte-server#render).
*
* */
export function onFrame<T>(fn: () => NotFunction<T> | Promise<NotFunction<T>> | (() => any)): void;
export function onAnimationFrame<T>(fn: () => NotFunction<T> | Promise<NotFunction<T>> | (() => any)): void;
/**
* Create a snippet programmatically
* */
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy