Skip to content
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

TypeError: undefined is not an object (evaluating 'next.length') #1258

Closed
flatsiedatsie opened this issue Sep 18, 2023 · 2 comments
Closed

Comments

@flatsiedatsie
Copy link

flatsiedatsie commented Sep 18, 2023

Describe the issue

When javascript code uses backticks, the code can disappear. I've been trying to narrow down what causes it.
I believe it has something to do with long strings in between backticks, or with code being in between two long backtick blocks.

TO REPRODUCE
Paste data from a table into a javascript variable that uses backquotes, so that the backquote variable becomes taller than the textarea.

  1. Open https://codemirror.net/
  2. Paste the below code into the example codemirror instance, replacing the old example code.
  3. Expand the area in between the first two backticks. You can try entering a couple of newlines, but for the best effect select some contents of a long html table and copy that into the variable (at 'paste over me'. The important thing is to make the content longer than the height of the textarea, so it overflows.
  4. Scroll up and down rapidly a few times.
  5. notice strange behaviour, or even a fully white editor. Clicking on it can resolve it, using arror keys can make it worse.

Copy this:

// codemirror issue when scrolling over long backtick variables
// let test = "a normal variable";    
let test = `	

paste over me
    
`




async function init_tf() {
    
    console.log("BEAUTY WORKER: LOADING BEAUTY TENSORFLOW MODEL");
    const LOCAL_MODEL_PATH = './models/beauty.json';
    //const HOSTED_MODEL_PATH = './models/beauty.json';
    
    //let model;
    try {
        model = await tf.loadLayersModel(LOCAL_MODEL_PATH);
        //window.model.summary();
        //beauty_detector_ready = true;
		postMessage({'loaded':'beauty'});
        
        
    } catch (err) {
        console.log("failed to load beauty scoring model:", err);
        //alert("failed to load beauty scoring model");
        document.getElementById('debug-log').innerHTML = "Error, beauty worker: failed to load model";
        
    }

}


init_tf();


onmessage = function(incoming) {
 	//console.log('Message received from main script');
  
  	var return_message = null;
  
	if (!model) {
		console.log("* no model loaded")
		return null;
	}
	else{
		//console.log("onmessage in beauty worker. Model was loaded. incoming data:");
		//console.log(incoming)
		
		/*
		result = incoming.data;
		console.log("incoming result object in web worker:");
		console.log(result);
		console.log(result.descriptor);
		*/
		if( 'data' in incoming ){
			//console.log("data in incoming beauty prediction");
			try{
				
				if( incoming.data.length == 128 ){
					//console.log("beauty worker: incoming data was 128 long");
					var vector_array = [];
			        for (var i = 0; i < incoming.data.length; i++) {
			            vector_array.push( incoming.data[i] );
			        }
					
					const shape = [1,128];

					// Run the normalized array through the model to get a prediction
				    let result = tf.tidy( () => {
						//console.log("predingting BMI now..");
				        //return model.predict( tf.stack( [ tf.tensor1d( normalized ) ] ) );
				        var a = tf.tensor(vector_array,shape,'float32');

				        const prediction = model.predict( a );
				        return_message = prediction.dataSync();
				    });
					
					//prediction.dispose();
			        //let prediction = await result.data();
					//console.log("result.data() = " + result.data());
					//let prediction = await result.data();
					//result.dispose();
			        
			        
					//console.log("beauty worker: prediction: " + return_message);
				}
				else{
					console.log("beauty worker: incoming data should be array of 128 floats (face fingerprint)");
				}
				
			}
			catch(e){
				console.log("error: beauty worker: " + e);
			}
		}		
		else{
			console.log("beauty worker: no data in incoming message");
		}
	}
	
	//var workerResult = 'Result: ' + (incoming.data[0] * incoming.data[1]);
	//console.log('Posting message back to main script');
	postMessage(return_message);
}


async function init_tf() {
    
    console.log("BEAUTY WORKER: LOADING BEAUTY TENSORFLOW MODEL");
    const LOCAL_MODEL_PATH = './models/beauty.json';
    //const HOSTED_MODEL_PATH = './models/beauty.json';
    
    //let model;
    try {
        model = await tf.loadLayersModel(LOCAL_MODEL_PATH);
        //window.model.summary();
        //beauty_detector_ready = true;
		postMessage({'loaded':'beauty'});
        
        
    } catch (err) {
        console.log("failed to load beauty scoring model:", err);
        //alert("failed to load beauty scoring model");
        document.getElementById('debug-log').innerHTML = "Error, beauty worker: failed to load model";
        
    }

}


init_tf();


onmessage = function(incoming) {
 	//console.log('Message received from main script');
  
  	var return_message = null;
  
	if (!model) {
		console.log("* no model loaded")
		return null;
	}
	else{
		//console.log("onmessage in beauty worker. Model was loaded. incoming data:");
		//console.log(incoming)
		
		/*
		result = incoming.data;
		console.log("incoming result object in web worker:");
		console.log(result);
		console.log(result.descriptor);
		*/
		if( 'data' in incoming ){
			//console.log("data in incoming beauty prediction");
			try{
				
				if( incoming.data.length == 128 ){
					//console.log("beauty worker: incoming data was 128 long");
					var vector_array = [];
			        for (var i = 0; i < incoming.data.length; i++) {
			            vector_array.push( incoming.data[i] );
			        }
					
					const shape = [1,128];

					// Run the normalized array through the model to get a prediction
				    let result = tf.tidy( () => {
						//console.log("predingting BMI now..");
				        //return model.predict( tf.stack( [ tf.tensor1d( normalized ) ] ) );
				        var a = tf.tensor(vector_array,shape,'float32');

				        const prediction = model.predict( a );
				        return_message = prediction.dataSync();
				    });
					
					//prediction.dispose();
			        //let prediction = await result.data();
					//console.log("result.data() = " + result.data());
					//let prediction = await result.data();
					//result.dispose();
			        
			        
					//console.log("beauty worker: prediction: " + return_message);
				}
				else{
					console.log("beauty worker: incoming data should be array of 128 floats (face fingerprint)");
				}
				
			}
			catch(e){
				console.log("error: beauty worker: " + e);
			}
		}		
		else{
			console.log("beauty worker: no data in incoming message");
		}
	}
	
	//var workerResult = 'Result: ' + (incoming.data[0] * incoming.data[1]);
	//console.log('Posting message back to main script');
	postMessage(return_message);
}





let old_source = `
English Wikipedia	English Wikipedia	English	Latn	en	120,580	15 January 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in English
German Wikipedia	Deutschsprachige Wikipedia	German	Latn	de	17,398	16 March 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in German
French Wikipedia	Wikipédia en français	French	Latn	fr	17,346	23 March 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in French
Spanish Wikipedia	Wikipedia en español	Spanish	Latn	es	13,965	20 May 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Spanish
Japanese Wikipedia	ウィキペディア日本語版
(Wikipedia nihongo-ban)	Japanese	Jpan	ja	13,879	20 May 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Japanese
Russian Wikipedia	Русская Википедия
(Russkaya Vikipediya)	Russian	Cyrl	ru	9,795	20 May 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Russian
Portuguese Wikipedia	Wikipédia em português	Portuguese	Latn	pt	8,447	11 May 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Portuguese
Chinese Wikipedia	Traditional Chinese: 中文維基百科,
simplified Chinese: 中文维基百科
(pinyin: Zhōngwén wéijī bǎikē)	Chinese
(written vernacular Chinese)	Hans/Hant	zh	7,846	24 October 2002	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Chinese
Italian Wikipedia	Wikipedia in italiano	Italian	Latn	it	7,718	11 May 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Italian
Persian Wikipedia	ویکی‌پدیای فارسی
(Vikipediyâ fārsi)	Persian	Arab	fa	5,247	19 December 2003	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Persian
Polish Wikipedia	Polskojęzyczna Wikipedia	Polish	Latn	pl	4,348	26 June 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Polish
Arabic Wikipedia	ويكيبيديا العربية
(Wīkībīdiyā al-ʿarabiyya)	Arabic	Arab	ar	4,125	8 July 2003	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Arabic
Dutch Wikipedia	Nederlandstalige Wikipedia	Dutch	Latn	nl	3,751	19 June 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Dutch
Ukrainian Wikipedia	Українська Вікіпедія
(Ukrayinsʹka Vikipediya)	Ukrainian	Cyrl	uk	3,497	30 January 2004	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Ukrainian
Hebrew Wikipedia	ויקיפדיה העברית
(Vikipedya ha-ivrit)	Hebrew	Hebr	he	3,135	8 July 2003	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Hebrew
Indonesian Wikipedia	Wikipedia bahasa Indonesia	Indonesian	Latn	id	3,069	30 March 2003	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Indonesian
Turkish Wikipedia	Türkçe Vikipedi	Turkish	Latn	tr	2,715	5 December 2002	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Turkish
Swedish Wikipedia	Svenskspråkiga Wikipedia	Swedish	Latn	sv	2,285	23 May 2001	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Swedish
Czech Wikipedia	Česká Wikipedie	Czech	Latn	cs	2,041	3 May 2002	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Czech
Vietnamese Wikipedia	Wikipedia tiếng Việt	Vietnamese	Latn	vi	1,918	November 2002 (unknown day)	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Vietnamese
Korean Wikipedia	한국어 위키백과
(Han-gugeo wikibaekgwa)	Korean	Hang	ko	1,805	11 October 2002	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Korean
Finnish Wikipedia	Suomenkielinen Wikipedia	Finnish	Latn	fi	1,576	21 February 2002	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Finnish
Hungarian Wikipedia	Magyar Wikipédia	Hungarian	Latn	hu	1,536	8 July 2003	
Wikipedia logo showing "Wikipedia: The Free Encyclopedia" in Hungarian
Simple English Wikipedia	Simple English Wikipedia	Simple English	Latn	simple	1,375	18 September 2001	
Wikipedia logo showing "Simple English Wikipedia" in English
Hindi Wikipedia	हिन्दी विकिपीडिया
(Hindī vikipīḍiyā)	Hindi	Deva	hi	1,207	11 July 2003
`

Screenshot 2023-09-18 at 12 55 00
Screenshot 2023-09-18 at 12 57 28

Browser and platform

MacOS, Both Safari and Brave are affected

Reproduction link

No response

@marijnh
Copy link
Member

marijnh commented Sep 20, 2023

Attached patch should help. In the end this had nothing to do with template strings or pasting, but your reproduction instructions helped me narrow it down.

@flatsiedatsie
Copy link
Author

Glad I could help! Thanks for the patch, I'll try to implement it. Loving codemirror so far! I only wish the documentation sometimes had examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants