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

Script tag in head causes error #75

Open
hoclun-rigsep opened this issue Dec 17, 2023 · 3 comments
Open

Script tag in head causes error #75

hoclun-rigsep opened this issue Dec 17, 2023 · 3 comments

Comments

@hoclun-rigsep
Copy link

Not a membrane issue per se but it cost me way too much of my life when trying to follow the "Membrane with WebGL target" doc: putting the script tag in the head rather than the body broke everything.

@phronmophobic
Copy link
Owner

Sorry that set you back. Do you have a stacktrace for the error you ran into? Maybe it's possible to update the code to work regardless of where the script tag is placed.

@hoclun-rigsep
Copy link
Author

I think it's just that the DOM isn't loaded yet, so document.body is undefined.

TypeError: Cannot read properties of null (reading 'appendChild')
    at Function.eval [as cljs$core$IFn$_invoke$arity$4] (webgl.cljs:162:24)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (webgl.cljs:141:5)
    at eval (webgl.cljs:165:2)
    at eval (<anonymous>)
    at goog.globalEval (main.js:434:11)
    at env.evalLoad (main.js:1405:12)
    at main.js:1568:12

In (load-font):

   (let [link (.createElement js/document "link")]
     (doto link
       (.setAttribute "rel" "stylesheet")
       (.setAttribute "href" stylesheet-url))
     (.appendChild (-> js/document .-body)            ; this throws
                   link))))

@phronmophobic
Copy link
Owner

Sounds good. The membrane.webgl namespace probably shouldn't do anything on load anyway. It seems like this issue and #49 can be fixed by:

  • Only running setup when necessary
  • Having setup make sure the page has loaded

With those changes, it should support any script tag location or loading mechanism.

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