Skip to content

fix(wc): apply stateMachineId and stateMachineConfig when set as properties - #1009

Open
pcbeingused333 wants to merge 2 commits into
LottieFiles:mainfrom
pcbeingused333:fix/wc-state-machine-property-setters
Open

pcbeingused333 wants to merge 2 commits into
LottieFiles:mainfrom
pcbeingused333:fix/wc-state-machine-property-setters

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Description

Setting stateMachineId or stateMachineConfig as a JavaScript property on <dotlottie-wc> / <dotlottie-worker-wc> after the animation has loaded has no effect: the state machine is never loaded, started, stopped or reconfigured. Only changing the attribute worked, because attributeChangedCallback was the only place that called stateMachineLoad/stateMachineStart/stateMachineStop and stateMachineSetConfig; the properties themselves were plain Lit fields. The React and Vue wrappers already react to changes of these props.

Fix: turn both into accessor properties whose setters apply the change to the player, the same way themeId and renderConfig already work, and remove the now-redundant attribute branches (attributes still reach the setter through Lit's attribute converter, so the player is called once per change).

Tests: adds a property-assignment case for each member, run for both elements. They fail on main (expected "stateMachineLoad" to be called 1 times, but got 0 times) and pass with the change; the existing attribute-based tests still pass.

Package(s) affected

  • @lottiefiles/dotlottie-web (core)
  • @lottiefiles/dotlottie-react
  • @lottiefiles/dotlottie-vue
  • @lottiefiles/dotlottie-svelte
  • @lottiefiles/dotlottie-solid
  • @lottiefiles/dotlottie-wc

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change
  • Chore (build, CI, docs, refactor)

Checklist

  • Changes have been tested locally
  • Tests have been added or updated
  • Changeset has been added (if applicable)

AI assistance was used to prepare this change.

…erties

The two members were plain Lit properties, so assigning them after the player was created never reached it; only the attribute path called stateMachineLoad/Start/Stop and stateMachineSetConfig. Move that logic into setters (as themeId and renderConfig already do) and drop the duplicate attribute branches.
@pcbeingused333
pcbeingused333 requested review from a team and theashraf as code owners November 19, 2026 06:46
@changeset-bot

changeset-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b8883e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lottiefiles/dotlottie-wc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

}

public set stateMachineId(value: Config['stateMachineId']) {
this._stateMachineId = value;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, tested on both elements and it works well.

One thing: the old attribute branch skipped when old === value. Now setting the same id again restarts the state machine. A guard here brings that back:

Suggested change
this._stateMachineId = value;
if (value === this._stateMachineId) return;
this._stateMachineId = value;

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants