LearnNewsExamplesServices
Frontmatter
id7153
titleIntroduce `attributeNameMap` for Robust Attribute Handling
stateClosed
labels
enhancement
assigneestobiu
createdAtAug 1, 2025, 3:01 PM
updatedAtAug 1, 2025, 3:02 PM
githubUrlhttps://github.com/neomjs/neo/issues/7153
authortobiu
commentsCount0
parentIssue7130
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtAug 1, 2025, 3:02 PM

Introduce attributeNameMap for Robust Attribute Handling

Closed v10.3.0 enhancement
tobiu
tobiu commented on Aug 1, 2025, 3:01 PM

1. Summary

Refactored src/functional/util/HtmlTemplateProcessor.mjs to use an attributeNameMap instead of a flat array for storing original attribute names. This change ensures correct mapping of dynamic values to their corresponding attributes, especially in complex scenarios involving nested templates and conditional rendering.

2. Rationale

Previously, the HtmlTemplateProcessor relied on a simple array (attributeNames) to track the original, case-sensitive names of attributes associated with dynamic values. This approach was prone to index shifting issues when falsy values were skipped or when nested templates were flattened, leading to incorrect attribute assignments (e.g., handler being mapped to style). By introducing an attributeNameMap that directly associates the dynamic value's index with its attribute name, we eliminate these synchronization problems, making the attribute parsing robust and reliable.

3. Scope & Implementation Plan

  1. Modify flattenTemplate: Change its return type to include an attributeNameMap (an object) instead of an attributeNames array.
  2. Populate attributeNameMap: Store dynamicValueIndex: attributeName pairs in the map within flattenTemplate, ensuring the attrMatch is recorded at the precise index where its corresponding dynamic value is pushed to flatValues.
  3. Handle Nested Templates: When flattening nested templates, adjust the keys of the nested attributeNameMap before merging them into the parent's map to maintain unique and correct indices across the entire flattened structure.
  4. Update convertNodeToVdom: Modify this method to retrieve the correct attribute name from the attributeNameMap using the dynamic value's index, rather than relying on a sequential attrNameIndex.
  5. Update JSDoc: Ensure all relevant JSDoc comments reflect the change from attributeNames to attributeNameMap.

4. Definition of Done

  • src/functional/util/HtmlTemplateProcessor.mjs uses attributeNameMap for attribute name tracking.
  • The style vs handler bug (and similar attribute mapping issues) is resolved.
  • The attribute mapping logic is robust against nested templates and conditional rendering.
  • All related JSDoc comments are updated to reflect the new attributeNameMap parameter.
tobiu assigned to @tobiu on Aug 1, 2025, 3:01 PM
tobiu added parent issue #7130 on Aug 1, 2025, 3:01 PM
tobiu added the enhancement label on Aug 1, 2025, 3:01 PM
tobiu referenced in commit 026026b - "Introduce attributeNameMap for Robust Attribute Handling #7153" on Aug 1, 2025, 3:02 PM
tobiu closed this issue on Aug 1, 2025, 3:02 PM