Skip to content

Component overrides parent data #3413

@smoldaner

Description

@smoldaner

Description:

If you pass undefined as a component attribute (required), and the component has initial data (data() { }) for this attribute, the parent context is overridden by this value.

Versions affected:

1.4.1

Platforms affected:

All

Reproduction:

See code below or this fiddle. The main ractive instance value1 data (undefined) is overridden by the components default value (42).

As Output I would expect

Value1:
Value2: Not undefined

instead of

Value1: 42
Value2: Not undefined

If the value is not undefined (value2), it works as expected

Code

const component = Ractive.extend({
  attribues: {
    required: ['value1', 'value2']
  },
  data () {
    return {
      value1: 42,
      value2: 42
    }
  }
})

const r = window.r = new Ractive({
  el: '#main',
  template: '#template',
  components: {
    component
  },
  data: {
    value1: undefined,
    value2: 'Not undefined'
  }
})

HTML

<script type="text/html" id="template">
  <h1>Value1: {{value1}}</h1>
  <h1>Value2: {{value2}}</h1>
  <component value1="{{value1}}" value2="{{value2}}"/>
</script>

<div id="main"></div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions