nextjournal / clerk

⚡️ Moldable Live Programming for Clojure
https://clerk.vision
ISC License
1.82k stars 78 forks source link

Confusing index behavior + cache invalidation with certain notebook links #559

Closed respatialized closed 9 months ago

respatialized commented 1 year ago

Overview

When clicking certain links in a notebook, I get bounced back to a missing index page, which also appears to invalidate the cache for that notebook.

Reproducible example

Data from kaggle, presumed to be in the relevant path.

cache_issue.clj


^{:nextjournal.clerk/toc true}
(ns respatialized.cache-issue
  (:require [nextjournal.clerk :as clerk]
            [tablecloth.api :as api]))

;; # Reading the data
^{::clerk/visibility {:result :hide}}
(def cc-data
  (time
   (api/dataset "resources/creditcard_csv.csv" )))

;; data from [kaggle](https://www.kaggle.com/datasets/joebeachcapital/credit-card-fraud)
(api/row-count cc-data)

;; # Plotting the data

(clerk/vl
 {:width 600 :height 600
  :title "histogram of amounts"
  :data {:values (-> cc-data
                     (api/head 2000)
                     (api/rows  :as-maps)) }
  :mark :bar
  :encoding {:x {:field "Amount" :binned true
                 :type :quantitative}
             :y {:aggregate "count"
                 :type :quantitative}}})

(comment

  (clerk/serve! {})

  (clerk/clear-cache!)

  (time
   (clerk/show! "src/respatialized/cache_issue.clj"))

  (throw (ex-info "error" {}))

  )

deps.edn

{:paths ["src"]
 :deps  {io.github.nextjournal/clerk {:git/url "https://github.com/nextjournal/clerk"
                                      :sha
                                      "0dae460df026080b1b3c923784af579ce7a6bc00"
                                      }
         scicloj/tablecloth {:mvn/version "7.007"}  
         }}

To reproduce

  1. start the notebook with clerk/serve!
  2. evaluate it with clerk/show!
  3. click "open in vega editor" link in the vega-lite viewer
  4. this should bounce the user to a page that says: No :nextjournal/clerk alias found in deps.edn. Learn how to set up your static build.
  5. re-evalute the page with clerk/show! this should take several seconds, indicating that the cache isn't being used.

I previously also observed this index issue when clicking TOC links, but cannot reproduce that issue with the above commit.

Expected behavior

I would like to stay on the same notebook page. Even if the cache still worked getting bounced to a nonexistent index page is confusing behavior that makes it harder to iterate on a notebook. Previous versions of Clerk did not exhibit this behavior.

Please let me know if you need me to elaborate or contextualize further.

j-minster commented 1 year ago

Hey, I just tried using this in deps.edn instead:

:deps {io.github.nextjournal/clerk {:mvn/version "0.14.919"}}

It's an older version on maven but it seems to not have this issue you mention. I had the same issue on the current maven version (0.15.957).

Hope that fixes it for you too until someone can find what causes the issue. My Clojure chops aren't enough to fix this at the minute.

zampino commented 9 months ago

This issue no longer reproduces as of current main c741fcd021c333d6d3fb2ba000cc04bb5d3e8251.