Repository navigation
fix: accept null/empty-string in fragments and harden test coverage - #130
Merged
Merged
Conversation
When html`${element}${null}${null}` produces a multi-root array,
_checkHtmlResult normalizes falsy values to '', but render() rejects
empty strings via its own falsy guard. Filter '' from the array output
so only meaningful renderable values reach the render paths.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
voxpelli
force-pushed
the
fix/html-template-value-type
branch
from
March 1, 2026 21:33
b5ce41a to
408c83b
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a rendering bug where multi-root html``...`` results could contain '' entries (from null/undefined/false interpolations), which then caused render() / renderToStringSync() to throw due to their non-falsy guards.
Changes:
- Filter
''values out of multi-root array results returned byhtml()to prevent render-time failures. - Introduce/extend template typing via
HtmlTemplateValueand add related type-level regression coverage. - Add runtime tests covering fragment interpolations for
null/false/undefinedin both async and sync render paths.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/htm.js | Filters empty-string entries from multi-root html() arrays; updates value typing for the internal htm binding. |
| lib/element-types.d.ts | Adds HtmlTemplateValue and adjusts ElementPropsValue Set/Map typing. |
| test/render-complex.spec.js | Adds async end-to-end tests for fragment interpolations (null/false/undefined) and removes now-unnecessary TS ignores. |
| test/sync-render.spec.js | Adds sync end-to-end tests for fragment interpolations (null/false). |
| test/html.spec.js | Adds an array-shape test asserting '' values are filtered from multi-root results; tweaks TS ignore comment. |
| test/async-render.spec.js | Removes TS ignore comments now covered by updated typing. |
| typetests/index.test.ts | Adds type regression tests for HtmlTemplateValue composition and Set/Map assignability. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Replace blunt `if (!item)` falsy check with proper typeof/Array.isArray
narrowing and assertTypeIsNever exhaustiveness guard. This fixes
Promise-resolved empty strings (e.g. `Promise.resolve('')`) being
incorrectly rejected — the Promise survives html()'s sync .filter()
but after await produces '' which the old falsy check threw on.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Align c8 ignore comment style, strengthen test assertions, and add missing test coverage for edge cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
htmltagged template correctly normalizes falsy interpolation values (null,undefined,false) to''via_checkHtmlResult, but multi-root fragments kept those empty strings in the returned arrayrender()rejects''via its own falsy guard (if (!item) throw), causinghtml${element}${null}${null}`` to throw at render time''from the array output inhtml()so only meaningful renderable values reach the render paths — fixes both sync and async paths automaticallyrender()/renderSync()to accept empty strings as validHtmlMethodResultCode review follow-ups
/* c8 ignore next */comment style with-- exhaustiveness guardannotation acrossrender.jsassert.equal(result.length, 1)withassert.deepEqual(result, [element])in array filtering testPromise.resolve(null)fragment test covering the async path (the stated PR motivation)renderToStringSync('')test mirroring the asyncrender('')testHtmlTemplateValueTest plan
Promise.resolve(null)fragment interpolationsfalseand symbol type assertions forHtmlTemplateValue(typetests/index.test.ts)🤖 Generated with Claude Code