Skip to content

Commit e7d241c

Browse files
committed
Detect and unwrap signal properties
1 parent d424e9c commit e7d241c

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

.changeset/mean-dragons-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-render-to-string': patch
3+
---
4+
5+
Fix support for signals, we need to detect and unwrap the signal

package-lock.json

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,8 @@
147147
},
148148
"publishConfig": {
149149
"provenance": true
150+
},
151+
"dependencies": {
152+
"@preact/signals-core": "^1.11.0"
150153
}
151154
}

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
SVG_CAMEL_CASE,
99
createComponent
1010
} from './lib/util.js';
11+
import { Signal } from '@preact/signals-core';
1112
import { options, h, Fragment } from 'preact';
1213
import {
1314
CHILDREN,
@@ -559,6 +560,7 @@ function _renderToString(
559560

560561
for (let name in props) {
561562
let v = props[name];
563+
v = isSignal(v) ? v.value : v;
562564

563565
if (typeof v == 'function' && name !== 'class' && name !== 'className') {
564566
continue;
@@ -740,3 +742,7 @@ const SELF_CLOSING = new Set([
740742
export default renderToString;
741743
export const render = renderToString;
742744
export const renderToStaticMarkup = renderToString;
745+
746+
function isSignal(x) {
747+
return x instanceof Signal;
748+
}

test/render.test.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ describe('render', () => {
143143
expect(rendered).to.equal(expected);
144144
});
145145

146+
it('should include boolean disabled attribute', () => {
147+
let rendered = render(<input disabled={false} />),
148+
expected = `<input/>`;
149+
150+
expect(rendered).to.equal(expected);
151+
});
152+
146153
it('should support false aria-* attributes', () => {
147154
let rendered = render(<div aria-checked={false} />);
148155
expect(rendered).to.equal(`<div aria-checked="false"></div>`);

test/signals/render.test.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import render from '../../src/index.js';
2+
import { signal } from '@preact/signals-core';
3+
import { h } from 'preact';
4+
import { expect, describe, it } from 'vitest';
5+
6+
/** @jsx h */
7+
8+
describe('signals', () => {
9+
it('should render signals', () => {
10+
const disabled = signal(false);
11+
12+
const vdom = <input draggable={false} disabled={disabled} />;
13+
14+
expect(render(vdom)).to.equal('<input draggable="false"/>');
15+
});
16+
});

0 commit comments

Comments
 (0)