-
-
Notifications
You must be signed in to change notification settings - Fork 97
Detect and unwrap signal properties #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'preact-render-to-string': patch | ||
--- | ||
|
||
Fix support for signals, we need to detect and unwrap the signal |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,5 +147,8 @@ | |
}, | ||
"publishConfig": { | ||
"provenance": true | ||
}, | ||
"dependencies": { | ||
"@preact/signals-core": "^1.11.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
SVG_CAMEL_CASE, | ||
createComponent | ||
} from './lib/util.js'; | ||
import { Signal } from '@preact/signals-core'; | ||
import { options, h, Fragment } from 'preact'; | ||
import { | ||
CHILDREN, | ||
|
@@ -559,6 +560,7 @@ function _renderToString( | |
|
||
for (let name in props) { | ||
let v = props[name]; | ||
v = isSignal(v) ? v.value : v; | ||
|
||
if (typeof v == 'function' && name !== 'class' && name !== 'className') { | ||
continue; | ||
|
@@ -740,3 +742,7 @@ const SELF_CLOSING = new Set([ | |
export default renderToString; | ||
export const render = renderToString; | ||
export const renderToStaticMarkup = renderToString; | ||
|
||
function isSignal(x) { | ||
return x instanceof Signal; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we should use duck-typing here like https://github.com/denoland/fresh/blob/e65643c482de9b5afee5d52af3ccc88941c35b5c/src/runtime/server/preact_hooks.tsx#L355-L362 . That way we can keep rts dependency free and don't have to keep it in sync with major There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might end up being a much larger perf hit in the critical path though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather avoid adding a dep for a singular If you've measured it & it is a perf issue, fair enough of course. I'll have some time in a bit to check the benches (if you haven't already). Edit: At least on my system, the check Marvin linked to above doesn't seem to perform any worse than |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import render from '../../src/index.js'; | ||
import { signal } from '@preact/signals-core'; | ||
import { h } from 'preact'; | ||
import { expect, describe, it } from 'vitest'; | ||
|
||
/** @jsx h */ | ||
|
||
describe('signals', () => { | ||
it('should render signals', () => { | ||
const disabled = signal(false); | ||
|
||
const vdom = <input draggable={false} disabled={disabled} />; | ||
|
||
expect(render(vdom)).to.equal('<input draggable="false"/>'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this was accidentally left around, will need to be removed but I gotta get to bed -- I can do it tomorrow but wanted to drop a mention at least so we don't release this.