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

circular dependency exception with viewers-without-lazy-loading example #289

Closed
ikappaki opened this issue Nov 19, 2022 · 3 comments
Closed

Comments

@ikappaki
Copy link
Contributor

Hi,

I was trying out to evade elission as per instructions from https://book.clerk.vision/#%F0%9F%94%93_elisions and notcied the following exception when viewers-without-lazy-loading is referenced in a notebook as a library call:

Unhandled clojure.lang.ExceptionInfo
   Circular dependency between issue/viewers-without-lazy-loading and
   issue/viewers-without-lazy-loading
   {:reason :weavejester.dependency/circular-dependency,
    :node issue/viewers-without-lazy-loading,
    :dependency issue/viewers-without-lazy-loading}

To reproduce

  1. In a new project, copy the viewers-without-lazy-loading fns from https://book.clerk.vision/ elission section in src/issue.clj file
(ns issue
  (:require [nextjournal.clerk.viewer :as v]))

(def without-pagination
  {:page-size #(dissoc % :page-size)})

(def viewers-without-lazy-loading
  (v/update-viewers v/default-viewers without-pagination))
  1. In a notebook/test.clj file, reference the viewers-without-lazy-loading fn
(ns test
  (:require [issue]))

issue/viewers-without-lazy-loading
  1. Load the web server, and attempt to show the notebeook, the above exception is thrown as per below
Unhandled clojure.lang.ExceptionInfo
   Circular dependency between issue/viewers-without-lazy-loading and
   issue/viewers-without-lazy-loading
   {:reason :weavejester.dependency/circular-dependency,
    :node issue/viewers-without-lazy-loading,
    :dependency issue/viewers-without-lazy-loading}
           dependency.cljc:   89  weavejester.dependency.MapDependencyGraph/depend
              analyzer.clj:  179  nextjournal.clerk.analyzer/analyze-circular-dependency/fn
                  core.clj: 6231  clojure.core/update
                  core.clj: 6223  clojure.core/update
              analyzer.clj:  176  nextjournal.clerk.analyzer/analyze-circular-dependency
              analyzer.clj:  171  nextjournal.clerk.analyzer/analyze-circular-dependency
              analyzer.clj:  192  nextjournal.clerk.analyzer/analyze-deps
              analyzer.clj:  185  nextjournal.clerk.analyzer/analyze-deps
                  core.clj: 2642  clojure.core/partial/fn
             protocols.clj:   49  clojure.core.protocols/iter-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6886  clojure.core/reduce
                  core.clj: 6868  clojure.core/reduce
              analyzer.clj:  263  nextjournal.clerk.analyzer/analyze-doc/fn
                Range.java:  180  clojure.lang.Range/reduce
                  core.clj: 6885  clojure.core/reduce
                  core.clj: 6868  clojure.core/reduce
              analyzer.clj:  241  nextjournal.clerk.analyzer/analyze-doc
              analyzer.clj:  236  nextjournal.clerk.analyzer/analyze-doc
              analyzer.clj:  238  nextjournal.clerk.analyzer/analyze-doc
              analyzer.clj:  236  nextjournal.clerk.analyzer/analyze-doc
              analyzer.clj:  357  nextjournal.clerk.analyzer/build-graph
              analyzer.clj:  351  nextjournal.clerk.analyzer/build-graph
                  eval.clj:  198  nextjournal.clerk.eval/+eval-results
                  eval.clj:  195  nextjournal.clerk.eval/+eval-results
                 clerk.clj:   58  nextjournal.clerk/show!
                 clerk.clj:   23  nextjournal.clerk/show!
                      REPL:   19  test/eval19960
                      REPL:   19  test/eval19960
             Compiler.java: 7194  clojure.lang.Compiler/eval
             Compiler.java: 7149  clojure.lang.Compiler/eval
                  core.clj: 3215  clojure.core/eval
                  core.clj: 3211  clojure.core/eval
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 1990  clojure.core/with-bindings*
                  core.clj: 1990  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   87  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  437  clojure.main/repl/read-eval-print/fn
                  main.clj:  437  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  218  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  217  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  833  java.lang.Thread/run

If I instead define the lazy fns inside the notebook, it works as expected without throwing, i.e.

(ns test2
  (:require [nextjournal.clerk.viewer :as v]))

(def without-pagination
  {:page-size #(dissoc % :page-size)})

(def viewers-without-lazy-loading
  (v/update-viewers v/default-viewers without-pagination))

viewers-without-lazy-loading

Thanks

@mk
Copy link
Member

mk commented Nov 21, 2022

This is actually an long-standing issue I've been meaning to fix but then forgot. The minimal repro is just referencing a var like clojure.core/inc. Thanks for the reminder.

mk added a commit that referenced this issue Nov 21, 2022
mk added a commit that referenced this issue Nov 21, 2022
@mk mk closed this as completed in c4e8836 Nov 22, 2022
@mk
Copy link
Member

mk commented Nov 22, 2022

@ikappaki the commit above should fix the issue. Thanks again for your excellent report and good to see you keep them coming!

@ikappaki
Copy link
Contributor Author

Thanks @mk, is working now.

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