Skip to content

Commit

Permalink
closes #2985
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Aug 25, 2023
1 parent d1dd1aa commit 6ada9d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/core/manage-component-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import {
evaluateAttributeExpressions,
isFunction,
isObject,
DOMattributesToObject,
} from '@riotjs/util'
import { addCssHook } from './add-css-hook.js'
import { bindDOMNodeToComponentInstance } from './bind-dom-node-to-component-instance.js'
import { computeComponentState } from './compute-component-state.js'
import { computeInitialProps } from './compute-initial-props.js'
import { createAttributeBindings } from './create-attribute-bindings.js'
import { runPlugins } from './run-plugins.js'
import { IS_DIRECTIVE } from '@riotjs/util/constants'

/**
* Component creation factory function that will enhance the user provided API
Expand Down Expand Up @@ -92,9 +94,15 @@ export function manageComponentLifecycle(
this[ATTRIBUTES_KEY_SYMBOL].update(parentScope)
}

const newProps = evaluateAttributeExpressions(
this[ATTRIBUTES_KEY_SYMBOL].expressions,
)
// Avoid adding the riot "is" directives to the component props
// eslint-disable-next-line no-unused-vars
const { [IS_DIRECTIVE]: _, ...newProps } = {
// make sure that the root node attributes will be always parsed
...DOMattributesToObject(this[ROOT_KEY]),
...evaluateAttributeExpressions(
this[ATTRIBUTES_KEY_SYMBOL].expressions,
),
}

if (this[SHOULD_UPDATE_KEY](newProps, this[PROPS_KEY]) === false)
return
Expand Down
5 changes: 5 additions & 0 deletions test/specs/state-and-props.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ describe('components state and props', () => {

expect(component.$('h1').innerHTML).to.be.equal('hello')

// check if static attributes persist also after an update call
// see also https://github.com/riot/riot/issues/2985
component.update()
expect(component.$('h1').innerHTML).to.be.equal('hello')

component.unmount()
})

Expand Down

0 comments on commit 6ada9d8

Please sign in to comment.