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

HTMLElement.style is readonly #44

Closed
willglynn opened this issue Nov 30, 2016 · 2 comments
Closed

HTMLElement.style is readonly #44

willglynn opened this issue Nov 30, 2016 · 2 comments

Comments

@willglynn
Copy link

willglynn commented Nov 30, 2016

I noticed the REPL wasn't working in Safari 10.0.1 (11602.2.14.0.7). Execution gets to:

function renderMainFragment ( root, component, target ) {
	var div = document.createElement( 'div' );
	div.setAttribute( 'svelte-1546246679', '' );
	div.className = "left";
	div.style = "width: " + ( root.verticalDividerPos ) + "%;";

…where it blows up with TypeError: Attempted to assign to readonly property.

This error appears to agree with the specs. CSS Object Model Level 2 defines the element style attribute to be readonly, offering mutability via the CSSStyleDeclaration provided by the style attribute rather than the style attribute itself. HTML5's global style attribute definition references CSSOM for the style IDL instead of explicitly stating it, though it includes a non-normative section describing style as having a getter with no setter:

element.style
Returns a CSSStyleDeclaration object for the element's style attribute.

MDN's style page describes "Setting style" as a thing which one can do, but explains that this is really just shorthand:

Styles can be set by assigning a string directly to the style property (as in elt.style = "color: blue;" ), which forwards it as el.style.cssText = "color:blue;", though it returns a CSSStyleDeclaration object which is read-only.

Probably this code should say .style.cssText="" instead of .style="".

@willglynn
Copy link
Author

I think that's here, needing a special case for assigning the style property?

@Rich-Harris
Copy link
Member

Ah, interesting! Thanks, fixed in 1.0.2. Have update the version used in the REPL too, it should update soon

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

No branches or pull requests

2 participants