Skip to content

docs: fix defineObservedAttributes example in attrs guide - #376

Open
Ultroncn wants to merge 1 commit into
github:mainfrom
Ultroncn:docs/fix-attrs-guide-define-observed-attributes
Open

Ultroncn wants to merge 1 commit into
github:mainfrom
Ultroncn:docs/fix-attrs-guide-define-observed-attributes

Conversation

@Ultroncn

Copy link
Copy Markdown

Closes #208

Hi Catalyst team! Thank you for maintaining Catalyst. The "What about without Decorators?" section in the attrs guide shows an example that cannot work as written: it calls defineObservedAttributes(HelloWorldElement, ['foo']), but defineObservedAttributes only takes the class — the second argument is silently ignored, and since no field was tagged with @attr, data-foo never makes it into observedAttributes, so attributeChangedCallback never fires for it. A reader copying the example would end up with an element that looks equivalent to the @attr version but never observes attribute changes.

This PR fixes the example to tag the field with attr() first (the workaround verified by the reporter in #208), then call defineObservedAttributes with just the class. attr, initializeAttrs, and defineObservedAttributes are all already publicly exported, so no code changes are needed — docs only, no behavior change.

Thank you for considering it, and please let me know if anything needs adjusting!

The no-decorators example called defineObservedAttributes with a
second argument that the function does not accept, so data-foo was
never observed. Tag the field with attr() first, as verified in github#208.

Closes github#208
@Ultroncn
Ultroncn requested a review from a team as a code owner November 17, 2026 00:38
Copilot AI adaptive review requested due to automatic review settings November 17, 2026 00:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the guide now documents the supported attr() registration with the corrected defineObservedAttributes() usage.

No open issues 🎉

What changed in this PR

Updates the attrs guide so the decorator-free example correctly registers foo for observation using attr() before calling defineObservedAttributes().

Changes:

  • Documents tagging the prototype property with attr() for observation.
  • Adds attr to the example import and invokes it on HelloWorldElement.prototype.
  • Removes the unsupported second argument from defineObservedAttributes().
File Description
docs/​_guide/​attrs.md Corrects the decorator-free attribute initialization and observation example.

Review effort: Lite (adaptive)

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.

Attrs are never observed unless added with @attr decorator

2 participants