sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.52k stars 1.91k forks source link

Allow playing transitions on initial render #2759

Open geoffrich opened 2 years ago

geoffrich commented 2 years ago

Describe the problem

In Svelte, you can play transitions on initial render by setting intro: true in the component constructor. There doesn't seem to be a way to do this in SvelteKit.

Describe the proposed solution

Add a setting in svelte.config.js that will set intro: true in the component constructor. This would only apply during the initial render. After client-side navigation, transitions should play automatically as components are mounted.

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

Conduitry commented 2 years ago

This has come up in Sapper (https://github.com/sveltejs/sapper/issues/1106) and I don't think the question of what this would mean for SvelteKit is any clearer.

nathancahill commented 2 years ago

Also interested in using this. I think it makes sense to implement with a browser check since the transitions wouldn't need to play in SSR.

mattcroat commented 2 years ago

Yes, please! 😄

divStar commented 2 years ago

I am wondering if I am actually also running into this issue at the moment.

I have a page, which has a date as URL parameter. If I switch to another page (actually just navigating to a route with a different date), a new view is created and each cell (in a month view) is animated.

However: when firing up the page directly via URL, it shows the first a loading animation and then instead of playing transitions as expected (e.g. in:fade), it just draws everything in a finished state. When moving, the animation is performed as expected.

Is it perhaps this limitation?

3mdistal commented 2 years ago

It's the same problem, yes. This library provides a hacky workaround you can use for now: https://fractils.fractal-hq.com/#OnMount

talwat commented 1 year ago

It might also be a good idea to be able to enable this functionality per-component or per-page. I really need this feature in my own project and it would be very nice to have.

gwerneckp commented 1 year ago

It's the same problem, yes. This library provides a hacky workaround you can use for now: https://fractils.fractal-hq.com/#OnMount

This works, but it prevents SSR. I get similar results by:

{#if someVar}
    <Component transition:someAnimation/>
{if}
jrhager84 commented 1 year ago

What's the status of this?

ioucyf commented 1 year ago

is it possible to revert back to svelte 3 until this is resolved? or is it going to break more things by doing so?

I'm on a completely empty sveltekit skeleton project. I'm starting fresh, but it comes with svelte 4.

socketopp commented 8 months ago

What's the status on this feature?

DaveKeehl commented 6 months ago

Any update? 👀

Spimy commented 5 months ago

There's still no way to do this after 3 years since this issue was opened? 😖

Andersama commented 5 months ago

I just ran into this after trying to update my svelte site, originally when clicking between links it seems like transitions were played per component being swapped in and out, allowing a pretty interesting visual when updating between pages. I'd really like to achieve the same effect with as minimal a code change as possible, I really like how it worked previously.

brittneypostma commented 3 months ago

Is this still being considered or is there a potential workaround?