File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -165,7 +165,8 @@ export const attributeToBuffer = (
165165 v : unknown ,
166166 tag ?: string
167167) : void => {
168- if ( v === null || v === undefined ) {
168+ // refs only make sense in the DOM
169+ if ( key === 'ref' || v === null || v === undefined ) {
169170 return
170171 }
171172 if ( typeof v === 'boolean' && booleanAttributes . has ( key ) ) {
@@ -175,7 +176,7 @@ export const attributeToBuffer = (
175176 return
176177 }
177178 if ( typeof v === 'function' ) {
178- if ( ! key . startsWith ( 'on' ) && key !== 'ref' ) {
179+ if ( ! key . startsWith ( 'on' ) ) {
179180 throw new Error (
180181 `Invalid prop '${ key } ' of type 'function' supplied to ${ tag ? `'${ tag } '` : 'a JSX element' } .`
181182 )
Original file line number Diff line number Diff line change @@ -482,6 +482,12 @@ describe('render to string', () => {
482482 expect ( template . toString ( ) ) . toBe ( '<div>Content</div>' )
483483 } )
484484
485+ it ( 'should be ignored used in ref props with a ref object' , ( ) => {
486+ const ref = { current : null }
487+ const template = < div ref = { ref } > Content</ div >
488+ expect ( template . toString ( ) ) . toBe ( '<div>Content</div>' )
489+ } )
490+
485491 it ( 'should raise an error if used in other props' , ( ) => {
486492 const onClick = ( ) => { }
487493 const template = < button data-handler = { onClick } > Click</ button >
Original file line number Diff line number Diff line change @@ -50,6 +50,11 @@ describe('jsx-runtime', () => {
5050 )
5151 } )
5252
53+ it ( 'Should render nothing for a ref in jsxAttr()' , ( ) => {
54+ expect ( String ( jsxAttr ( 'ref' , { current : null } as never ) ) ) . toBe ( '' )
55+ expect ( String ( jsxAttr ( 'ref' , ( ( ) => { } ) as never ) ) ) . toBe ( '' )
56+ } )
57+
5358 it ( 'Should render nothing for a null style object in jsxAttr()' , ( ) => {
5459 expect ( String ( jsxAttr ( 'style' , null as never ) ) ) . toBe ( '' )
5560 } )
You can’t perform that action at this time.
0 commit comments