@@ -104,7 +104,6 @@ export class CodeBlockWidget extends React.Component<
104104 }
105105
106106 render ( ) {
107-
108107 const { state } = this . context as { state : any } ;
109108 const textAreaStyle : CSS . Properties = {
110109 width : this . state . width ,
@@ -146,32 +145,11 @@ export class CodeBlockWidget extends React.Component<
146145 > </ CardHeader >
147146 < CardContent className = "p-0" >
148147 < div className = "block-basic-code-parameters" >
149- { this . props . node . getParameters ( ) . map ( ( port ) => {
150- console . error ( 'Port is undefined or null' , port ) ;
151- return (
152- < BasePort
153- className = "code-parameter-port"
154- port = { port ! }
155- engine = { this . props . engine }
156- isInput = { true }
157- key = { port ?. getID ( ) }
158- > </ BasePort >
159- ) ;
160- } ) }
148+ { this . renderPortsSafely ( 'parameters' ) }
161149 </ div >
162150 < div className = "grid-container" >
163151 < div className = "block-basic-code-inputs" >
164- { this . props . node . getInputs ( ) . map ( ( port , index ) => {
165- return (
166- < BasePort
167- className = "code-input-port"
168- port = { port ! }
169- engine = { this . props . engine }
170- isInput = { true }
171- key = { port ?. getID ( ) }
172- > </ BasePort >
173- ) ;
174- } ) }
152+ { this . renderPortsSafely ( 'inputs' ) }
175153 </ div >
176154 < div
177155 className = "block-basic-code-textarea-container"
@@ -187,27 +165,11 @@ export class CodeBlockWidget extends React.Component<
187165 defaultValue = { this . state . code }
188166 onChange = { this . handleInput }
189167 theme = "vs-dark"
190- // options={{
191- // "readOnly": state.locked,
192- // "minimap": {
193- // "enabled": false
194- // }
195- // }}
196168 />
197169 </ div >
198170
199171 < div className = "block-basic-code-outputs" >
200- { this . props . node . getOutputs ( ) . map ( ( port ) => {
201- return (
202- < BasePort
203- className = "code-output-port"
204- port = { port ! }
205- engine = { this . props . engine }
206- isInput = { false }
207- key = { port ?. getID ( ) }
208- > </ BasePort >
209- ) ;
210- } ) }
172+ { this . renderPortsSafely ( 'outputs' ) }
211173 </ div >
212174 </ div >
213175 </ CardContent >
@@ -217,6 +179,128 @@ export class CodeBlockWidget extends React.Component<
217179 ) ;
218180 }
219181
182+
183+ /**
184+ * Port'ları güvenli şekilde render et
185+ */
186+ private renderPortsSafely = ( portType : 'parameters' | 'inputs' | 'outputs' ) => {
187+ try {
188+ let ports : any [ ] = [ ] ;
189+ let isInput = true ;
190+ let className = '' ;
191+
192+ switch ( portType ) {
193+ case 'parameters' :
194+ ports = this . props . node . getParameters ( ) || [ ] ;
195+ className = 'code-parameter-port' ;
196+ isInput = true ;
197+ break ;
198+ case 'inputs' :
199+ ports = this . props . node . getInputs ( ) || [ ] ;
200+ className = 'code-input-port' ;
201+ isInput = true ;
202+ break ;
203+ case 'outputs' :
204+ ports = this . props . node . getOutputs ( ) || [ ] ;
205+ className = 'code-output-port' ;
206+ isInput = false ;
207+ break ;
208+ }
209+
210+ // Null/undefined port'ları filtrele
211+ const validPorts = ports . filter ( port => {
212+ if ( ! port ) {
213+ console . warn ( `${ portType } port is null or undefined:` , port ) ;
214+ return false ;
215+ }
216+ return true ;
217+ } ) ;
218+
219+ return validPorts . map ( ( port , index ) => {
220+ // Port ID'sini güvenli şekilde al
221+ const portId = port ?. getID ?.( ) || `${ portType } -${ index } ` ;
222+
223+ // Port render'ında hata kontrolü
224+ try {
225+ return (
226+ < BasePort
227+ className = { className }
228+ port = { port }
229+ engine = { this . props . engine }
230+ isInput = { isInput }
231+ key = { portId }
232+ />
233+ ) ;
234+ } catch ( error ) {
235+ console . error ( `Error rendering ${ portType } port:` , error , port ) ;
236+ return null ;
237+ }
238+ } ) ;
239+ } catch ( error ) {
240+ console . error ( `Error in renderPortsSafely for ${ portType } :` , error ) ;
241+ return [ ] ;
242+ }
243+ }
244+
245+ /**
246+ * Component lifecycle - componentDidUpdate
247+ * Port güncellemelerini handle et
248+ */
249+ componentDidUpdate ( prevProps : CodeBlockWidgetProps ) {
250+ // Node data değişikliklerini kontrol et
251+ if ( this . props . node !== prevProps . node ) {
252+ this . forceUpdate ( ) ;
253+ }
254+
255+ // Port sayısında değişiklik varsa yeniden render et
256+ const prevPortCount = this . getPortCount ( prevProps . node ) ;
257+ const currentPortCount = this . getPortCount ( this . props . node ) ;
258+
259+ if ( prevPortCount !== currentPortCount ) {
260+ console . log ( 'Port count changed, forcing re-render' ) ;
261+ setTimeout ( ( ) => {
262+ this . forceUpdate ( ) ;
263+ } , 100 ) ;
264+ }
265+ }
266+
267+ /**
268+ * Port sayısını hesapla
269+ */
270+ private getPortCount = ( node : any ) => {
271+ try {
272+ const inputs = node . getInputs ( ) ?. length || 0 ;
273+ const outputs = node . getOutputs ( ) ?. length || 0 ;
274+ const parameters = node . getParameters ( ) ?. length || 0 ;
275+ return inputs + outputs + parameters ;
276+ } catch ( error ) {
277+ console . error ( 'Error getting port count:' , error ) ;
278+ return 0 ;
279+ }
280+ }
281+
282+ /**
283+ * Component will unmount - cleanup
284+ */
285+ componentWillUnmount ( ) {
286+ // Port listener'larını temizle
287+ try {
288+ const allPorts = [
289+ ...( this . props . node . getInputs ( ) || [ ] ) ,
290+ ...( this . props . node . getOutputs ( ) || [ ] ) ,
291+ ...( this . props . node . getParameters ( ) || [ ] )
292+ ] ;
293+
294+ allPorts . forEach ( port => {
295+ if ( port && port . clearListeners ) {
296+ port . clearListeners ( ) ;
297+ }
298+ } ) ;
299+ } catch ( error ) {
300+ console . error ( 'Error during component cleanup:' , error ) ;
301+ }
302+ }
303+
220304 /**
221305 * Callback when code input field changes
222306 * @param event Change event from Code text area
0 commit comments