Skip to content

FIX 3 bugs related to getters and classes#471

Open
serhumanos wants to merge 2 commits into
alpine-collective:masterfrom
serhumanos:fix/nested-getters-context
Open

FIX 3 bugs related to getters and classes#471
serhumanos wants to merge 2 commits into
alpine-collective:masterfrom
serhumanos:fix/nested-getters-context

Conversation

When a getter in a child Alpine.js component references its own
properties using 'this', the devtools extension was incorrectly
using only the parent's context, causing 'this' to point to the
parent instead of the component itself.

The fix collects the child's own non-getter properties first, then
creates a combined context (parent + child, with child taking
precedence) before evaluating getters. This matches Alpine.js's
actual runtime behavior.

Before:
- Getter in child accessing this.childProp → undefined (wrong)
- Getter in child accessing this.parentProp → works (correct)

After:
- Getter in child accessing this.childProp → works (correct)
- Getter in child accessing this.parentProp → works (correct)
@serhumanos serhumanos marked this pull request as draft June 13, 2026 02:42
- Modified getAlpineDataInstance() to traverse the prototype chain and capture getters, methods, and properties inherited from classes.

- Updated watchComponents() to use getAllEnumerablePropertyNames(), which also traverses the prototype chain, allowing detection of changes in inherited properties.

- This enables using Alpine.data() with instances of classes that extend base components (e.g., WizardPasoComponent) while maintaining full visibility in the devtools.
@serhumanos serhumanos changed the title fix(backend): correct 'this' context in nested component getters FIX 3 bugs related to getters and classes Jun 13, 2026
@serhumanos serhumanos marked this pull request as ready for review June 13, 2026 02:54
@serhumanos serhumanos closed this Jun 13, 2026
@serhumanos serhumanos deleted the fix/nested-getters-context branch June 13, 2026 03:06
@serhumanos serhumanos restored the fix/nested-getters-context branch June 13, 2026 03:11
@serhumanos

Copy link
Copy Markdown
Author

Added the fix #472

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.

1 participant