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

Source map lines wrong after some time #871

Closed
mtruyens opened this issue Apr 16, 2021 · 8 comments
Closed

Source map lines wrong after some time #871

mtruyens opened this issue Apr 16, 2021 · 8 comments

Comments

@mtruyens
Copy link

Something that I've noticed for quite a while in ShadowCLJS is that the reported source code line numbers in the browser console (e.g., in case of exceptions thrown in the browser) are getting offset after a couple of hot reloading modifications. When I then refresh the browser, the problem is solved.

I do not seem to find anything about this issue in the manual or the Github issues. Am I the only one encountering it?

@thheller
Copy link
Owner

No clue, more information and a reproducible example would help.

@or
Copy link

or commented May 12, 2021

I've finally managed to reproduce this. I took a boot example and added a shadow-cljs configuration: https://github.com/or/boot-cljs-example

boot -u
boot dev

and

yarn install
npx shadow-cljs watch main

I've added this code to fail:
https://github.com/or/boot-cljs-example/blob/master/src/app/core.cljs#L5-L8

With the boot dev server I see:
Screen Shot 2021-05-12 at 16 29 20

With shadow-cljs:
Screen Shot 2021-05-12 at 16 29 31

Note that boot jumps to line 6, which is correct, but shadow jumps to line 8.

I've looked at the source maps and decoded them. For boot, download http://localhost:3000/main.out/app/core.js.map and:

< core.js.map decode-source-map | jq -S
...
    "6": [
      "1 => core.cljs 4:3 js/document",
      "1 => core.cljs 5:5 js/document",
      "16 => core.cljs 6:6 js/document",
      "49 => core.cljs 6:6 js/document",
      "54 => core.cljs 6:6 js/document",
      "57 => core.cljs 6:6 js/document",
      "16 => core.cljs 6:7 clojure.string/replace",
      "76 => core.cljs 7:6 clojure.string/replace",
      "109 => core.cljs 7:6 clojure.string/replace",
      "115 => core.cljs 7:6 clojure.string/replace",
      "119 => core.cljs 7:6 clojure.string/replace",
      "76 => core.cljs 7:7 clojure.string/replace",
      "139 => core.cljs 8:6 clojure.string/replace",
      "172 => core.cljs 8:6 clojure.string/replace",
      "178 => core.cljs 8:6 clojure.string/replace",
      "182 => core.cljs 8:6 clojure.string/replace",
      "139 => core.cljs 8:7 clojure.string/replace"
    ],
    "7": [
      ""
    ],
    "8": [
      "1 => core.cljs 10:5 clojure.string/replace",
      "4 => core.cljs 10:5 clojure.string/replace",
      "19 => core.cljs 10:5 clojure.string/replace",
      "2 => core.cljs 10:11 c"
    ],
...

for shadow-cljs

< app.core.js.map decode-source-map | jq -S
    "4": [
      "1 => app/core.cljs 4:3 js/document",
      "1 => app/core.cljs 5:5 js/document",
      "1 => app/core.cljs 6:6 js/document",
      "1 => app/core.cljs 6:6 js/document",
      "1 => app/core.cljs 6:6 js/document",
      "1 => app/core.cljs 6:6 js/document",
      "1 => app/core.cljs 6:7 clojure.string/replace",
      "1 => app/core.cljs 7:6 clojure.string/replace",
      "1 => app/core.cljs 7:6 clojure.string/replace",
      "1 => app/core.cljs 7:6 clojure.string/replace",
      "1 => app/core.cljs 7:6 clojure.string/replace",
      "1 => app/core.cljs 7:7 clojure.string/replace",
      "1 => app/core.cljs 8:6 clojure.string/replace",
      "1 => app/core.cljs 8:6 clojure.string/replace",
      "1 => app/core.cljs 8:6 clojure.string/replace",
      "1 => app/core.cljs 8:6 clojure.string/replace",
      "1 => app/core.cljs 8:7 clojure.string/replace"
    ],
    "5": [
      ""
    ],
    "6": [
      "1 => app/core.cljs 10:5 clojure.string/replace",
      "1 => app/core.cljs 10:5 clojure.string/replace",
      "1 => app/core.cljs 10:5 clojure.string/replace",
      "1 => app/core.cljs 10:11 c"
    ],

So my understanding is that there's the generated JS file, and on line X at column Y of it some error happens, in the boot case something like X = 6, Y = 16, then it looks up the entries for line 6 in the mappings, and in there finds the closest column entry <= 16 (guessing on the exact operation), which then points to "core.cljs 6:7 clojure.string/replace".

But in my shadow-cljs generated source-maps all the columns are mapped to "1", so it jumps to the last one in that chunk. Which in MANY cases still will be the correct line, perhaps even roughly the same column, which is why it isn't noticeable in many situations.

I've used shadow-cljs 2.12.6 in the example and various older shadow-cljs versions I tried (back to 2.8.x).

@thheller
Copy link
Owner

Please upgrade the boot example to use CLJS 1.10.844. It is using completely ancient versions. I don't even know how far back you'd have to go with shadow-cljs to get those versions but I think it was still 1.x era.

[org.clojure/clojure         "1.7.0"]
[org.clojure/clojurescript   "1.7.228"]

Also what is the decode-source-map tool?

@thheller
Copy link
Owner

Also the example code produces 3 warnings? One cannot expect proper source maps for improper code?

------ WARNING #1 - :undeclared-var --------------------------------------------
 File: /mnt/c/Users/thheller/code/tmp/boot-cljs-example/src/app/core.cljs:6:7
--------------------------------------------------------------------------------
   3 | (defn main []
   4 |   (let [c (.. js/document (createElement "DIV"))]
   5 |     (str
   6 |      (clojure.string/replace nil "" "")
-------------^------------------------------------------------------------------
 Use of undeclared Var clojure.string/replace
--------------------------------------------------------------------------------
   7 |      (clojure.string/replace "foo" "f" "b")
   8 |      (clojure.string/replace "bar" "b" "f"))
   9 |
  10 |     (aset c "innerHTML" "<p>i'm dynamically created</p>")
--------------------------------------------------------------------------------

------ WARNING #2 - :undeclared-var --------------------------------------------
 File: /mnt/c/Users/thheller/code/tmp/boot-cljs-example/src/app/core.cljs:7:7
--------------------------------------------------------------------------------
   4 |   (let [c (.. js/document (createElement "DIV"))]
   5 |     (str
   6 |      (clojure.string/replace nil "" "")
   7 |      (clojure.string/replace "foo" "f" "b")
-------------^------------------------------------------------------------------
 Use of undeclared Var clojure.string/replace
--------------------------------------------------------------------------------
   8 |      (clojure.string/replace "bar" "b" "f"))
   9 |
  10 |     (aset c "innerHTML" "<p>i'm dynamically created</p>")
  11 |     (.. js/document (getElementById "container") (appendChild c))))
--------------------------------------------------------------------------------

------ WARNING #3 - :undeclared-var --------------------------------------------
 File: /mnt/c/Users/thheller/code/tmp/boot-cljs-example/src/app/core.cljs:8:7
--------------------------------------------------------------------------------
   5 |     (str
   6 |      (clojure.string/replace nil "" "")
   7 |      (clojure.string/replace "foo" "f" "b")
   8 |      (clojure.string/replace "bar" "b" "f"))
-------------^------------------------------------------------------------------
 Use of undeclared Var clojure.string/replace
--------------------------------------------------------------------------------
   9 |
  10 |     (aset c "innerHTML" "<p>i'm dynamically created</p>")
  11 |     (.. js/document (getElementById "container") (appendChild c))))
  12 |
--------------------------------------------------------------------------------

@or
Copy link

or commented May 12, 2021

The boot dependencies are upgraded.

https://github.com/bengourley/source-map-decoder

@or
Copy link

or commented May 12, 2021

Warnings are fixed now.

@thheller
Copy link
Owner

Found some old compiler hack code that got out of sync with CLJS.

Should be fixed in 2.12.7.

Thanks for the repro.

@or
Copy link

or commented May 12, 2021

Awesome, just tried it and all's well.
Thanks for the swift fix!

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

3 participants