1

The problem

I'm using innerHTML to put HTML-formatted text in a <div>. At a consistent, seemingly random point in the text, the fonts stop being rendered and display blank. When I select the invisible text, it reappears.

Description of the code

  1. We have a single <div id="text" inner-h-t-m-l="[[markup]]">.
  2. The initial markup doesn't contain any data apart from empty segments with IDs:

    <div id="segment-1"></div><div id="segment-2"></div>... etc

  3. In Javascript, we loop over the IDs using querySelector (this is slow) and insert HTML into the each segment's innerHTML.

The framework used is Polymer 2.

Additional info; video

In the Chrome Dev Tools, the invisible text is shown as present in the DOM and seems to be no different from the text that renders correctly.

The font in the video is non-standard, but the problem also occurs when using system fonts.

Here's a video to illustrate the problem.

Here's a screenshot of a Chrome profiler run:

chrome profiler screenshot

Edit:

After a discussion in the comments, I thought I should link the actual code.

Here's the element in question.

The relevant parts are:

  • <div id="segmented_text_content" inner-h-t-m-l="[[markup]]"></div>
  • _addPrimaryText(textStrings) {...}
  • _addSecondaryText(textStrings) {...}

Edit 2:

I found two potential workarounds for this, but neither one works well enough.

  1. If I run this.querySelector('#text').innerHTML = this.querySelector('#text').innerHTML with a timeout of 3 seconds, it paints the text correctly.

  2. When adding the text, if I use the async processArray function from this comment, it renders the text correctly, albeit very slowly because it updates the layout after every insertion.

With these two points, my working theory now is that Chrome updates the layout before the innerHTML attribute is fully assigned.

I also forgot to mention this project uses Shady DOM.

Hubert
  • 485
  • 7
  • 14
  • What do you mean by "invisible text"? Is the attribute actually set to `inner-h-t-m-l="[[markup]]"` at `
    `?
    – guest271314 Nov 05 '17 at 22:44
  • It can be seen in the video. The text is there in the DOM, the mouse cursor changes to the caret when hovering over it, but it doesn't paint on the screen for some reason, it's just white like the background. – Hubert Nov 05 '17 at 22:45
  • Have not viewed the video. Can you include full HTML, JavaScript and CSS at Question and reproduce issue at stacksnippets? – guest271314 Nov 05 '17 at 22:46
  • Your question is quite clear as to the nature of the problem, so anyone who has seen exactly this problem somewhere else might be able to help, but in the likely event that doesn't happen we're going to need more code in your question to see what could be causing the behavior. – James Nov 05 '17 at 22:48
  • Yes, the attribute is initially set to `markup`. I tried, but was not able to reproduce this issue on any of the snippets sites. [Here's](https://github.com/suttacentral/next-sc/blob/development/client/elements/text/sc-segmented-text.html) the actual Polymer code of the element in question. – Hubert Nov 05 '17 at 22:49
  • Are you able to post rendered html, css, javascript that reproduce the problem – James Nov 05 '17 at 23:17

0 Answers0