Skip to content
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

Style properties update unnecessarily #3433

Closed
Rich-Harris opened this issue Aug 20, 2019 · 1 comment
Closed

Style properties update unnecessarily #3433

Rich-Harris opened this issue Aug 20, 2019 · 1 comment
Labels

Comments

@Rich-Harris
Copy link
Member

Describe the bug

Svelte generates code that updates style properties when nothing could change.

To Reproduce

https://svelte.dev/repl/fa82902dbf5e442a92217e6d6fa6c078?version=3.8.1

Expected behavior

Given this code...

<script>
	let color = 'red';
</script>

<h1 class={color} style="color: {color}">color: {color}</h1>

...no update could should be generated, since color could not change. This works correctly for regular attributes:

	return {
		c() {
			h1 = element("h1");
			t0 = text("color: ");
			t1 = text(color);
			attr(h1, "class", "" + null_to_empty(color) + " svelte-1fyrt1w");
			set_style(h1, "color", color);
		},

		m(target, anchor) {
			insert(target, h1, anchor);
			append(h1, t0);
			append(h1, t1);
		},

-		p(changed, ctx) {
-			if (changed.color) {
-				set_style(h1, "color", color);
-			}
-		},
-
+		p: noop,
		i: noop,
		o: noop,

		d(detaching) {
			if (detaching) {
				detach(h1);
			}
		}
	};

Severity

Minor

@Rich-Harris
Copy link
Member Author

closed via #3439

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant