# Shadow-cljs release build: how to troubleshoot issues with Google Closure advanced optimizations?

**URL:** https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407
**Category:** Troubleshooting
**Tags:** clojurescript
**Created:** [August 16, 2020, 9:11am UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407 "2020-08-16T09:11:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jackdbd](https://clojureverse.org/user_avatar/clojureverse.org/jackdbd/32/5556_2.png) [@jackdbd](https://clojureverse.org/u/jackdbd)
#### Post date: [August 16, 2020, 9:11am UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407/1 "2020-08-16T09:11:22Z")

</div>

I’m developing a simple Reagent SPA with a Firebase Firestore backend. The app shows a list of quotes (for now they are just fakes I created with Faker.js) and features infinite scrolling.

Basically there are 2 steps involeved when fetching data from Firestore:

1. The app fetches a single batch of quotes from Firestore as soon as it mounts in the DOM. It’s not a Firestore subscription, it’s a Firestore one-time query, so no Firestore subscription is involved.
2. When the user scrolls past a certain threshold, the callback of a IntersectionObserver kicks in, and the app fetches the next batch of quotes.

Both step 1 and 2 work as expected when I run `shadow-cljs watch app`, or when I create a release build with `:compiler-options {:optimizations :simple}`. However, only step 1 works fine when I create a release build with `:compiler-options {:optimizations :advanced}` (the default option for shadow-cljs).

To put it in other terms, the Firestore query (step 1) still works, but infinite scrolling (step 2) breaks when I compile the app with Google Closure’s advanced optimizations.

My understanding is that Google Closure advanced optimizations strip away some symbols and break step 2.

My question is: how can I debug what broke step 2? Can you recommend any resources to understand what’s going on with Google Closure advanced optimizations?

I found [this handbook](https://github.com/roman01la/closure-compiler-handbook), but before committing to read it I’d like to know what other options I might have.

Thanks!

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [August 16, 2020, 10:15am UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407/2 "2020-08-16T10:15:54Z")

</div>

The most likely cause of your problems are missing [Externs](https://shadow-cljs.github.io/docs/UsersGuide.html#externs).

Definitely turn on `:infer-externs :auto` and you should be getting warnings as described in the guide. This is enabled by default in newer versions (2.10.15+).

You don’t need to read the closure compiler handbook because it is not relevant to shadow-cljs.

---

<div class="post-metadata">

### Author: ![jackdbd](https://clojureverse.org/user_avatar/clojureverse.org/jackdbd/32/5556_2.png) [@jackdbd](https://clojureverse.org/u/jackdbd)
#### Post date: [August 16, 2020, 2:10pm UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407/3 "2020-08-16T14:10:06Z")

</div>

Thanks, I completely skipped that part of the documentation.  
I have just tried `:auto` and I get no warnings. With `:all` I get plenty of warnings though (from reagent, core.async, accountant, clerk).  
Tomorrow I’ll try to understand what’s going on.

Kudos for shadow-cljs. It’s an amazing tool and the documentation is top-notch!

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [August 17, 2020, 9:33am UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407/4 "2020-08-17T09:33:24Z")

</div>

Don’t use `:all`.

You can try `shadow-cljs release app --pseudo-names`. If that fixes things then it is likely that some of the generated code clashes with something else that is already on your page. Do you have any other JS code loaded on the page?

---

<div class="post-metadata">

### Author: ![jackdbd](https://clojureverse.org/user_avatar/clojureverse.org/jackdbd/32/5556_2.png) [@jackdbd](https://clojureverse.org/u/jackdbd)
#### Post date: [August 17, 2020, 6:17pm UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407/5 "2020-08-17T18:17:44Z")

</div>

Now everything works fine, either if I use `--pseudo-names` or not. I’m not sure what fixed the issue.

In my index.html I download Firebase and several Firebase SDKs with a `<script defer />`. I am using `defer` for the app’s bundle too (I am not doing any code splitting). I didn’t change anything here.

The last changes I did on the app were: I removed [stacktrace.js](http://www.stacktracejs.com/), added the [React integration for Sentry](https://docs.sentry.io/platforms/javascript/react/), added [glogi](https://github.com/lambdaisland/glogi) for logging.  
I was using StackTrace.js because I was sending the stackframes to shadow-cljs Inspect with `tap>`. Now I just send them to Sentry.

By the way, I saw that `--pseudo-names` calls `.setGeneratePseudoNames` for the Closure compiler options, but I couldn’t find any documentation, only this [javadoc](https://javadoc.io/doc/com.google.javascript/closure-compiler/v20181210/com/google/javascript/jscomp/CompilerOptions.html#setGeneratePseudoNames-boolean-) with no explanation.

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [August 17, 2020, 9:01pm UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407/6 "2020-08-17T21:01:42Z")

</div>

“pseudo-names” still renames everything it would usually rename, just in a way that lets you recognize what the original name was. So instead of renaming `cljs.core.assoc` to something short like `xF` it renames to `$cljs$core$assoc$`. This is meant to help spot rename problems where `xF` is accidentally clashing with some other javascript on the page. If you have including other scripts on the page that tends to happen sometimes. Much less likely to clash with the longer name. It is just a debugging aid and makes the code rather large so it should not be used in production.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [February 16, 2021, 9:01am UTC](https://clojureverse.org/t/shadow-cljs-release-build-how-to-troubleshoot-issues-with-google-closure-advanced-optimizations/6407/7 "2021-02-16T09:01:45Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
