mnater / Hyphenopoly

Hyphenation for node and Polyfill for client-side hyphenation.
http://mnater.github.io/Hyphenopoly/
MIT License
694 stars 44 forks source link

not blocking error "TypeError: Cannot read property 'list' of undefined" #125

Closed sapyx closed 4 years ago

sapyx commented 4 years ago

Browser: Google Chrome 81.0.4044.138

TypeError: Cannot read property 'list' of undefined
    at hyphenateLangElements (c:\Users\Sapyx\Dropbox\HTML\Pierini\js\hyphens\Hyphenopoly.js:663:37)
    at prepareLanguagesObj (c:\Users\Sapyx\Dropbox\HTML\Pierini\js\hyphens\Hyphenopoly.js:773:14)
    at handleWasm (c:\Users\Sapyx\Dropbox\HTML\Pierini\js\hyphens\Hyphenopoly.js:858:18)

but the hypenation is correct.

<script>
        var Hyphenopoly = {
            require: { "it": "FORCEHYPHENOPOLY" },
            setup: { selectors: { "section>p": {} } },
            paths: { maindir: "./js/hyphens/" },
            handleEvent: {
                hyphenopolyEnd: function () {
                    document.getElementById("stampa").disabled = false;
                }
            }
        };
    </script>
mnater commented 4 years ago

Looks like an issue with selectors. Please post your HTML, too.

sapyx commented 4 years ago

This is an excerpt from HTML, which is very long. I don't know if I had said it before but in the end the result is perfect. Only this error message appears in the console. By performing a debug, the error occurs first and, afterwards, the procedure is repeated and completed correctly.

<!DOCTYPE html>
<html lang="it">

<head>
    <meta charset="UTF-8">
</head>

<body>
    <main>
        <div class="pure-g">
            <div id="colonna-testo" class="pure-u-1 pure-u-md-1-2 pure-u-lg-1-3 colonne">
                <article>
                    <section>
                        <h2>Introduzione</h2>
                        <h3>Accesso a uno spazio potenzialmente infinito...</h3>
                        <p>Internet da circa un decennio, sebbene con fasi alterne e con differenze da sottile a
                            macroscopiche, è diventato casa di un numero incalcolabile di pubblicazioni.</p>
                    </section>
                </article>
            </div>
        </div>
    </main>
</body>
sapyx commented 4 years ago

i forgot to say that i am using paged.js and an old version of Hyphenopoly (provided in an example of paged.js) works perfectly.

sapyx commented 4 years ago

After further investigation, I can confirm that the error does not always happen, but in a random way (by continuing to reload the page), and it is never blocking. Screenshot 2020-05-16 14 05 30

mnater commented 4 years ago

I think I found the problem. If the .wasm-engine is loaded before the DOM is ready, Hyphenopoly tries to hyphenate the elements of the specified language, but these elements aren't loaded, yet. So it produces that error message. Later, when the DOM is ready, Hyphenopoly collects the elements and hyphenates them.

paged.js delays DOM-readyness. I haven't covered this case in my tests, yet 🤦‍♂️