Svelte: Skip transitions on initial render

Created on 1 May 2017  路  8Comments  路  Source: sveltejs/svelte

Particularly in the case of components that are replacing server-rendered HTML, you might want transitions to only run when data changes, rather than running when the component is first rendered.

Best way to do this is presumably with a directive along these lines...

<div in:fade initialintro:skip>...</div>

...except a little bit more concise. Any ideas?

transitions

Most helpful comment

Yeah, my plan is for no initial transitions to be the default (enabled with intro: true in the init options for your top-level component, and <WIdget in:true/> below that). It'd be a breaking change though, so in the interim there probably needs to be a compiler option, just like we had with cascade: false and store: true prior to v2.

Am hoping to work on transitions again this weekend.

All 8 comments

Could skip be an optional property on the animation similar to delay, duration, etc.?

<div in:fade='{ initial: false }'>...</div>

or maybe more generic

<div in:fade='{ enabled: false }'>...</div>

The component.observe method takes the parameter { init: false } to skip the initial trigger. We could go with consistency here: <div in:fade='{ init: false }'>...</div>.

Leaving this here: https://vuejs.org/v2/guide/transitions.html#Transitions-on-Initial-Render

<div appear in:fade></div>

I would expect no initial transition by default because how can something transition if there were no state/route changes?

I agree with @thgh and was going to add a comment about the same. The default should be no transition on initial render. Transitions are mostly used to help the user of an app track changes and are not used for initial render as often.

While I do think the default ought to be skipping the initial render transition, I would really like to have this soon and am ok with the default being no skip. I'm almost done with refactoring over to Svelte and this is the last user-visible issue I need fixed before I can launch in a few weeks. If there is a workaround I am open to that too.

Update: I can help out with it too! I'll check things out in a couple weeks when I'm done and see what I can contribute.

Yeah, my plan is for no initial transitions to be the default (enabled with intro: true in the init options for your top-level component, and <WIdget in:true/> below that). It'd be a breaking change though, so in the interim there probably needs to be a compiler option, just like we had with cascade: false and store: true prior to v2.

Am hoping to work on transitions again this weekend.

What would be amazing.

As of 2.6 the skipIntroByDefault compiler prevents intros from running during the initial render. This will be the default in v3.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rich-Harris picture Rich-Harris  路  3Comments

st-schneider picture st-schneider  路  3Comments

matt3224 picture matt3224  路  3Comments

thoughtspile picture thoughtspile  路  3Comments

AntoninBeaufort picture AntoninBeaufort  路  3Comments