From 9d557785e31b018f4d148e7feb79f4ad1a091d0b Mon Sep 17 00:00:00 2001 From: Daniel Kaspo Date: Wed, 31 May 2017 19:58:03 -0400 Subject: [PATCH 1/2] linkify in markup.js now adds keys to multiple links. Notably, LID "VIEWWALLET_Subtitle" was causing an issue here, since it had more than one link. React was complaining about it but now it's all good. --- common/translations/markup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/translations/markup.js b/common/translations/markup.js index e7589ae8..5cf096d1 100644 --- a/common/translations/markup.js +++ b/common/translations/markup.js @@ -22,7 +22,7 @@ function linkify(mdString: string) { let i = 0; while (i + 1 < parts.length) { result.push(decodeHTMLEntities(parts[i])); - result.push({parts[i + 1]}); + result.push({parts[i + 1]}); i += 3; } result.push(decodeHTMLEntities(parts[parts.length - 1])); From 608f50ae1c4f6273e445be3a2c73e8bc9588089c Mon Sep 17 00:00:00 2001 From: Daniel Kaspo Date: Wed, 31 May 2017 20:46:03 -0400 Subject: [PATCH 2/2] Added keys for bolding and linking for markup.js If you were to mix-and-match or use multiple markdown elements in one string, this would cause a React key error. This fixes it by key-ing all the things! --- common/translations/markup.js | 8 ++++++-- spec/translations/markup.spec.js | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/common/translations/markup.js b/common/translations/markup.js index 5cf096d1..4ac25947 100644 --- a/common/translations/markup.js +++ b/common/translations/markup.js @@ -19,10 +19,12 @@ function linkify(mdString: string) { return decodeHTMLEntities(parts[0]); } const result = []; + let key = 0; let i = 0; while (i + 1 < parts.length) { result.push(decodeHTMLEntities(parts[i])); - result.push({parts[i + 1]}); + result.push({parts[i + 1]}); + key++; i += 3; } result.push(decodeHTMLEntities(parts[parts.length - 1])); @@ -35,10 +37,12 @@ export function markupToReact(mdString: string) { return linkify(parts[0]); } let result = []; + let key = 0; let i = 0; while (i + 1 < parts.length) { result = result.concat(linkify(parts[i])); - result.push({parts[i + 2]}); + result.push({parts[i + 2]}); + key++; i += 3; } result = result.concat(linkify(parts.pop())); diff --git a/spec/translations/markup.spec.js b/spec/translations/markup.spec.js index 9c4427ac..9476eebd 100644 --- a/spec/translations/markup.spec.js +++ b/spec/translations/markup.spec.js @@ -10,47 +10,47 @@ describe('markupToReact', () => { it('transforms bold syntax', () => { let value = '**foo**'; - let expected = [foo]; + let expected = [foo]; expect(markupToReact(value)).toEqual(expected); value = '**foo** bar'; - expected = [foo, ' bar']; + expected = [foo, ' bar']; expect(markupToReact(value)).toEqual(expected); value = 'bar **foo**'; - expected = ['bar ', foo]; + expected = ['bar ', foo]; expect(markupToReact(value)).toEqual(expected); value = 'bar **foo** baz'; - expected = ['bar ', foo, ' baz']; + expected = ['bar ', foo, ' baz']; expect(markupToReact(value)).toEqual(expected); value = '**foo****bar**'; - expected = [foo, bar]; + expected = [foo, bar]; expect(markupToReact(value)).toEqual(expected); }); it('transforms link syntax', () => { let value = '[foo](http://google.com)'; - let expected = [foo]; + let expected = [foo]; expect(markupToReact(value)).toEqual(expected); value = '[foo](http://google.com) bar'; - expected = [foo, ' bar']; + expected = [foo, ' bar']; expect(markupToReact(value)).toEqual(expected); value = 'bar [foo](http://google.com)'; - expected = ['bar ', foo]; + expected = ['bar ', foo]; expect(markupToReact(value)).toEqual(expected); value = 'bar [foo](http://google.com) baz'; - expected = ['bar ', foo, ' baz']; + expected = ['bar ', foo, ' baz']; expect(markupToReact(value)).toEqual(expected); value = '[foo](http://google.com)[bar](http://google.ca)'; expected = [ - foo, - bar + foo, + bar ]; expect(markupToReact(value)).toEqual(expected); }); @@ -59,9 +59,9 @@ describe('markupToReact', () => { let value = 'Bold **foo** link [foo](http://google.com) text'; let expected = [ 'Bold ', - foo, + foo, ' link ', - foo, + foo, ' text' ]; expect(markupToReact(value)).toEqual(expected);