Repository navigation
Conversation
…ter @controller Closes github#207 initializeAttrs guarded re-initialization with a per-element flag, so once @controller had initialized the @attr-decorated names, a later call with additional names — for example, from the element's own connectedCallback, the documented pattern for attrs without the @attr decorator — was silently ignored and those properties were never bound to their data-* attributes. Track initialized names per element instead of a single flag: a later call now initializes just the names that have not been initialized yet, while names that were already initialized are left alone (which keeps the re-initialization guard that attributeChangedCallback relies on). Names are marked before their descriptor is defined so a re-entrant call cannot define the same name twice.
There was a problem hiding this comment.
🟡 Changes recommended
Reflecting missing decorated defaults re-enters initialization through attributeChangedCallback, causing repeated scans of all decorated names and quadratic initialization work.
1 open issue
What changed in this PR
This PR addresses #207 by allowing manual attribute initialization after @controller has initialized decorated properties.
Changes:
- Tracks initialized property names per element so later calls can add bindings.
- Marks names before defining descriptors to prevent duplicate initialization during re-entrant calls.
- Adds regression tests for manual binding, default reflection, and repeated calls.
| File | Description |
|---|---|
test/attr.ts |
Adds three tests for manual initialization after @controller. |
src/attr.ts |
Replaces the per-element guard with per-name tracking and documents incremental initialization. |
Review effort: Balanced (adaptive)
Comment on lines
+59
to
+60
| if (initialized.has(key)) continue | ||
| initialized.add(key) |
Author
|
Thanks for catching this, and for the detailed explanation! You are
right — reflecting the missing defaults re-enters initializeAttrs
through attributeChangedCallback, and each pass rescans every
decorated name. I will keep a fast path so implicit initialization
short-circuits once it is in progress or complete, while explicit
calls can still initialize additional names. I will update the PR
shortly.
…On Mon, 16 Nov 2026 19:25:43 -0800, Copilot ***@***.***> wrote:
@Copilot commented on this pull request.
<!-- ccr-overview-v2 -->
### 🟡 Changes recommended
Reflecting missing decorated defaults re-enters initialization through attributeChangedCallback, causing repeated scans of all decorated names and quadratic initialization work.
<details open>
<summary><strong>1 open issue</strong></summary>
- <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> [Avoid repeated full scans during attribute initialization](#379 (comment)) · New
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR addresses #207 by allowing manual attribute initialization after ***@***.***` has initialized decorated properties.
**Changes:**
- Tracks initialized property names per element so later calls can add bindings.
- Marks names before defining descriptors to prevent duplicate initialization during re-entrant calls.
- Adds regression tests for manual binding, default reflection, and repeated calls.
| File | Description |
| ---- | ----------- |
| `test/attr.ts` | Adds three tests for manual initialization after ***@***.***`. |
| `src/attr.ts` | Replaces the per-element guard with per-name tracking and documents incremental initialization. |
</details>
<sub>Review effort: Balanced (adaptive)</sub>
> + if (initialized.has(key)) continue
+ initialized.add(key)
Reflecting missing decorated defaults synchronously invokes `attributeChangedCallback`, which calls `initializeAttrs` again (`src/core.ts:78`). Each reaction now scans all decorated names, making initialization quadratic with nested calls; subsequent observed mutations also scan every name. Retain an in-progress/completed fast path for implicit decorated-name initialization while allowing explicit calls to initialize additional names.
--
Reply to this email directly or view it on GitHub:
#379 (review)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
… done Reflecting a missing decorated default back to an attribute synchronously invokes attributeChangedCallback, which calls initializeAttrs again with no names. Each re-entrant call rescanned every decorated name, making initialization quadratic with nested calls, and every later observed mutation rescanned them too. Track implicit initialization per element (in-progress/completed) and short-circuit implicit calls on either state, so only the outermost call scans the decorated names. Explicit calls are never short-circuited and still initialize the names they are given. If the loop throws part-way, the state is dropped so a later implicit call retries the remaining names.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #207
@controllercallsinitializeAttrsfor the@attr-decorated names as soon as the element connects. A later call with additional names — for example, from the element's ownconnectedCallback, the documented pattern for attrs without the@attrdecorator (seedocs/_guide/attrs.md, "What about without Decorators?") — was silently ignored, because re-initialization was guarded by a single per-element flag. Those properties were never bound to theirdata-*attributes and kept their field defaults (in the issue's example,openstayedtruedespitedata-open="false").This changes the guard to track initialized names per element instead of a single flag, so a later call initializes just the names that have not been initialized yet. Names that were already initialized are left alone, which keeps the guard that
attributeChangedCallbackrelies on (it callsinitializeAttrson every attribute change). Names are marked before their descriptor is defined so a re-entrant call — for example, one triggered by reflecting the default value back to an attribute — cannot define the same name twice.Testing
test/attr.ts("manual initialization"): a manually initialized attr reads itsdata-*attribute value, reflects its default value when no attribute is present, and repeated calls do not re-initialize it.npx web-test-runner test/attr.ts: 15 passed (12 existing + 3 new).npx eslint src/attr.ts test/attr.tsandnpx tsc --noEmit: clean.