This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm start- Start development server on http://localhost:8080npm run lint- Run ESLint with zero warnings tolerancenpm run lint-fix- Auto-fix ESLint issuesnpm test- Run tests with tap-parser formattingnpm run type- Run TypeScript type checkingnpm run performance- Run automated performance tests via puppeteer (requires server to be running)./bump.sh- Bump version and create release
The npm run performance command runs automated performance tests using puppeteer. It requires the development server to be running (npm start) and supports these options:
--frames=<number>- Number of animation frames to run (default: 100)--delay=<number>- Delay between test phases in ms (default: 1000)--timing=<mode>- Timing mode: 'raf' or 'fixed' (default: 'fixed')--skip=<group>- Skip test group: 'inject', 'initial', or 'update'
Examples:
npm run performance
npm run performance -- --frames=50 --timing=raf
npm run performance -- --skip=inject --skip=initialResults are saved to:
performance/performance.json- Standard performance resultsperformance/performance-profile.json- Detailed profiling data (if profiling is enabled)
Important Performance Testing Notes:
- Use the
--profile=trueflag to focus on this library's performance (chrome profiling results are also output). - Performance results can be volatile and unstable with default settings
- For reliable measurements when optimizing, use more frames:
--frames=200or higher - Run tests multiple times and compare medians to account for noise
- System load, browser state, and other factors affect timing measurements
- Focus on consistent trends across multiple runs rather than single measurements
- Always confirm your performance testing findings with a larger
--framescount. And, run it twice to be very certain. It's easy for a single run to produce poor results and lead you astray!
- You can assume that the development server will already be running. This is standard for developers to do in this repository.
This is x-element, a minimal custom element base class library built on web standards with zero dependencies. The architecture consists of three main modules:
-
x-element.js - Main XElement base class
- Provides property system with reflection, observation, and computed properties
- Manages element lifecycle (constructor analysis, initialization, updates)
- Handles templating integration and DOM rendering
- Supports declarative event listeners
-
x-parser.js - HTML template parser
- Strict parser for tagged template literals
- Validates HTML structure and prevents common mistakes
- Generates tokens for template engine consumption
- Supports custom element names and standard HTML elements
-
x-template.js - Default template engine
- Efficient DOM diffing and updates
- Supports various binding types (attributes, properties, content, boolean)
- Handles arrays, keyed lists, and nested templates
- Character reference decoding and fragment management
Properties have extensive configuration options:
type- Type checking and coercionattribute- Attribute-property synchronizationreflect- Property-to-attribute reflectioncompute/input- Computed properties with dependenciesobserve- Property change callbacksinitial/default- Default value handlingreadOnly/internal- Access control
- Uses native template literals with
htmltagged templates - Supports interpolation in text content, attributes, and properties
- Special syntax:
?attr(boolean),??attr(defined),.prop(property) - Automatic DOM diffing and minimal updates
- Built-in support for arrays and keyed lists
Tests are located in /test directory with individual HTML files for each test suite. Tests use a custom testing framework (@netflix/x-test) and run in the browser environment.
- To test a specific test, you should test through
npm testand then find the relevant lines in the output.
- Zero compilation step required
- Minimal, generalized functionality
- Few opinionated design decisions
- Assumes browser expertise (stays out of the way)
- Follows web platform precedents
- Compatible with all modern browsers supporting custom elements
- Simple, commented code
- No proprietary learning required
- Zero dependencies
TypeScript definitions are generated and available in /types directory:
- x-element.d.ts
- x-parser.d.ts
- x-template.d.ts
The /demo directory contains examples showing different template engines and use cases:
- Basic hello-world example
- Chess piece component
- Performance comparisons with React, lit-html, uhtml
- Integration examples for different templating approaches
The x-parser.js file should be valid in the latest LTS for Node and the latest
versions of Chrome, Firefox, and Safari. The x-template.js and x-element.js
files should be valid in the latest versions of Chrome, Firefox, and Safari.
- Simple looping functions are more performant than even loops like
for .. of - Switch statements are more performant for small enumerations of known values than a map, the browser heavily optimizes this
- The files that you may want to fetch from the server are exactly the files in the repository where you should consider the project root as equivalent to the web server root. I.e., you do not need to web-fetch the test links to look at the code, you can just read the files in the repository.
- While it might be tempting to stop using comments as DOM cursors — the current two-cursor approach offers robustness and predictability for DOM manipulation.
- Use the
--suffixargument to save things like--suffix=beforeand--suffix=afterfor easier A/B testing. Don't forget to clean up these files after you are finished with all your tasks.