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

Fix Code Splitting example for ClojureScirpt 1.11+ #334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dawranliou
Copy link

@dawranliou dawranliou commented Aug 26, 2022

This PR fixes the following two things:

Incorrect script paths in Index.html

Figwheel serves the static files from the target/public/ folder so the
target prefix in the target/cljs-out/*.js script src paths are incorrect.
This commit fixes the script paths in the index.html host page so the browser
doesn't show 404 responses for the compiled js files.

goog.dom.createDom error in cljs 1.11+

The goog.dom/createDom function requires a second argument of
opt_attributes. (See official documentation at
https://google.github.io/closure-library/api/goog.dom.html.) In previous
ClojureScript versions, the goog.dom/createDom function was able to handle the
nonexistence of opt_attributes argument, miraculously. However, with
ClojureScript 1.11.60, this is considered an error:

dom.js:171 Uncaught TypeError: Cannot set property assignedSlot of #<Element> which has only a getter
    at dom.js:171:20
    at Object.forEach (object.js:11:7)
    at goog.dom.setProperties (dom.js:156:15)
    at goog.dom.createDom_ (dom.js:264:16)
    at goog.dom.createDom (dom.js:252:19)
    at foo$core$listen_to_button (core.cljs:11:17)
    at core.cljs:23:16

This PR fixes the errors above and is tested on both ClojureScript 1.11.60
and ClojureScript 1.10.773.

See https://github.com/dawranliou/figwheel-main-code-splitting-demo for the
working demo.

Figwheel serves the static files from the `target/public/` folder so the
`target` prefix in the `target/cljs-out/*.js` script src paths are incorrect.
This commit fixes the script paths in the index.html host page so the browser
doesn't show 404 responses for the compiled js files.
The goog.dom/createDom function requires a second argument of `opt_attributes`.
(See at https://google.github.io/closure-library/api/goog.dom.html.)  In
previous ClojureScript versions, the goog.dom/createDom function was able to
handle the nonexistence of `opt_attributes` argument, miraculously.  However,
with ClojureScript 1.11.60, this is considered an error:

dom.js:171 Uncaught TypeError: Cannot set property assignedSlot of #<Element> which has only a getter
    at dom.js:171:20
    at Object.forEach (object.js:11:7)
    at goog.dom.setProperties (dom.js:156:15)
    at goog.dom.createDom_ (dom.js:264:16)
    at goog.dom.createDom (dom.js:252:19)
    at foo$core$listen_to_button (core.cljs:11:17)
    at core.cljs:23:16

This commit fixes the error above and is tested on both ClojureScript 1.11.60
and ClojureScript 1.10.773.
@dawranliou dawranliou changed the title Fix Code Splitting example - index.html Fix Code Splitting example for ClojureScirpt 1.11+ Aug 26, 2022
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

Successfully merging this pull request may close these issues.

1 participant