Skip to content

Using imported object for style attribute is reevaluated if other attribute uses updated signal #1938

Description

@aquaductape

Describe the bug

As the title, when using imported object for element style attribute, it is reevaluated if other attributes that use signal that is updated.

In this example a button element style uses an imported object called style which has background value of red.

export const style = {
  "background": "red",
}

After the button is mounted then it's background is changed to blue via element style property.

import { style } from "./style"

// ...
onMount(() => {
  buttonEl.style.background = 'blue'
})

return (
  <button style={style} ... ref={buttonEl}>
    {count()}
  </button>
);
}

This button's aria-label attribute uses count signal which increments when clicked

const [count, setCount] = createSignal(1);
const increment = () => setCount(count() + 1);
let buttonEl;

onMount(() => {
  buttonEl.style.background = 'blue'
})

return (
  <button type="button" onClick={increment} aria-label={count().toString()} style={style} ref={buttonEl}>
    {count()}
  </button>

Your Example Website or App

https://playground.solidjs.com/anonymous/804fbf3b-2166-430f-ab99-c2b78770a1a6

Steps to Reproduce the Bug or Issue

  1. Click counter button

Expected behavior

For button's background color to remain blue, but after clicking button it resets red which is the background property from object style. If button style attribute uses style2 object, which is not imported then the button remains blue after updating count signal https://playground.solidjs.com/anonymous/efc28da8-a36c-42e5-b109-5d7b8a8c145e.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 118.0.5993.117

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions