Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite7d241c

Browse files
committed
Detect and unwrap signal properties
1 parentd424e9c commite7d241c

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 aboutcustomizing 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(letnameinprops){
561562
letv=props[name];
563+
v=isSignal(v) ?v.value :v;
562564

563565
if(typeofv=='function'&&name!=='class'&&name!=='className'){
564566
continue;
@@ -740,3 +742,7 @@ const SELF_CLOSING = new Set([
740742
exportdefaultrenderToString;
741743
exportconstrender=renderToString;
742744
exportconstrenderToStaticMarkup=renderToString;
745+
746+
functionisSignal(x){
747+
returnxinstanceofSignal;
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+
letrendered=render(<inputdisabled={false}/>),
148+
expected=`<input/>`;
149+
150+
expect(rendered).to.equal(expected);
151+
});
152+
146153
it('should support false aria-* attributes',()=>{
147154
letrendered=render(<divaria-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+
importrenderfrom'../../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+
constdisabled=signal(false);
11+
12+
constvdom=<inputdraggable={false}disabled={disabled}/>;
13+
14+
expect(render(vdom)).to.equal('<input draggable="false"/>');
15+
});
16+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp