Skip to content

@starting-style not supported in <style> blocksΒ #9267

@jrmoynihan

Description

@jrmoynihan

Describe the bug

Given this style block:

<style>
	@starting-style{
		.card{
			opacity: 0;
			height: 0;
		}
	}	
	.card {
		background-color: orange;
		max-width: max-content;
		padding: 1rem;
		border-radius: 1rem;
		display: grid;
		margin: auto;
		transform-origin: bottom;
		overflow: hidden;
		transition: opacity 1s, display 1s, height 1s;
		transition-behavior: allow-discrete;
	}
</style>

Svelte outputs the following CSS:

@starting-style{}.card.svelte-1xboevw{background-color:orange;max-width:max-content;padding:1rem;border-radius:1rem;display:grid;margin:auto;transform-origin:bottom;overflow:hidden;transition:opacity 1s, display 1s, height 1s;transition-behavior:allow-discrete}

Note the empty ruleset within the @starting-style block. This rule is required to enable discrete entry transitions e.g. from display: none. Ideally, Svelte should be adding a scoped .card.svelte-[hash] rule within that block to the stylesheet.

Moreover, supporting this declaration would also likely help unlock more performant transitions directives provided by Svelte itself, without the need for JS functions.

Possibly related:
#8587

Reproduction

Not Working (Svelte)
https://svelte.dev/repl/74f096b3e2884455b47b9e6a2e6b24e9?version=4.2.1
Working (Codepen)
https://codepen.io/jrmoynihan/pen/jOXxeWG?editors=1111

Logs

No response

System Info

Chrome 117+, MacOS, Svelte 4.2.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    cssStuff related to Svelte's built-in CSS handling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions