You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: Exposing a beforeCommit Hook in Solid (e.g. for View Transitions)
#4772
However, I think it may be worthwhile to expose a minimal, lower-level API that gives library authors the flexibility to build their own abstractions around Solid's commit lifecycle and explore different high-level API designs.
This low-level API remains useful even if Solid adopts an official ViewTransition API, though it risks constraining Solid's internals.
Proposal
I propose adding a new option to createMemo, called beforeCommit, which is a callback that is executed just before Solid commits a new value.
Proposed behavior
Solid does not await the completion of beforeCommit, even if it performs asynchronous work. The commit proceeds independently of the callback's completion.
Multiple memos can have beforeCommit callbacks running simultaneously.
Note that scoped view transitions are currently only available in Chromium-based browsers, and Firefox support for even basic view transitions is currently shaky .
Once a beforeCommit callback has been invoked, the corresponding new value is guaranteed to be committed to the reactive graph before beforeCommit is invoked again for a subsequent, newer value.
Solid ignores exceptions thrown by beforeCommit.
Parameters
The beforeCommit callback receives the arguments:
The value that is about to be committed.
A promise that resolves once the new value has been committed to the reactive graph, including the execution of render effects (i.e., the corresponding DOM updates).
Example
Here is an example of how this API could be used to support view transitions with an asynchronously derived value:
constasyncDerived=createMemo<T>(()=>asyncFunction(input()),{beforeCommit: async(newValue: T,afterCommit: Promise<void>)=>{// pre-view-transition work// Reading asyncDerived() here produces current value, not newValueconstviewTransition=document.startViewTransition(async()=>{// during-view-transition workawaitafterCommit;});awaitviewTransition.finished;// after-view-transition work},},);
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I saw in view transitions proposal that the goal, post v2.0, is to implement a
ViewTransitionAPI similar to React's.However, I think it may be worthwhile to expose a minimal, lower-level API that gives library authors the flexibility to build their own abstractions around Solid's commit lifecycle and explore different high-level API designs.
This low-level API remains useful even if Solid adopts an official
ViewTransitionAPI, though it risks constraining Solid's internals.Proposal
I propose adding a new option to
createMemo, calledbeforeCommit, which is a callback that is executed just before Solid commits a new value.Proposed behavior
beforeCommit, even if it performs asynchronous work. The commit proceeds independently of the callback's completion.beforeCommitcallbacks running simultaneously.beforeCommitcallback has been invoked, the corresponding new value is guaranteed to be committed to the reactive graph beforebeforeCommitis invoked again for a subsequent, newer value.beforeCommit.Parameters
The
beforeCommitcallback receives the arguments:Example
Here is an example of how this API could be used to support view transitions with an asynchronously derived value:
All reactions