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

Server-Side-Rendering Improvements #396

Merged
merged 16 commits into from
Jan 31, 2023
Merged

Server-Side-Rendering Improvements #396

merged 16 commits into from
Jan 31, 2023

Conversation

zampino
Copy link
Collaborator

@zampino zampino commented Jan 31, 2023

  • Fix occurrence of unguarded js/document access
  • Report SSR progress and duration
  • Add smoke test on CI for SSR

@zampino
Copy link
Collaborator Author

zampino commented Jan 31, 2023

A simple notebook like rule_30.clj or viewers/html.clj works now (after e70414d), but only if using the js release:

(build-static-app! {:ssr? true
                    :compile-css? true
                    :resource->url {"/js/viewer.js" "./build/viewer.js"}
                    :index "notebooks/rule_30.clj"})

while with live js

(build-static-app! {:ssr? true
                    :compile-css? true
                    :resource->url {"/js/viewer.js" "./public/js/viewer.js"}
                    :index "notebooks/rule_30.clj"})

I'm getting:

Clerk ssr! failed

(node:82128) ExperimentalWarning: Network Imports is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
file:///Users/amantini/dev/clerk/public/js/cljs-runtime/nextjournal.clerk.render.hooks.js:256
(x98957.cljs$core$IDeref$ = cljs.core.PROTOCOL_SENTINEL);
                          ^

TypeError: Cannot add property cljs$core$IDeref$, object is not extensible
    at Object.nextjournal$clerk$render$hooks$specify_atom_BANG_ [as specify_atom_BANG_] (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/nextjournal.clerk.render.hooks.js:256:27)
    at Function.cljs$core$IFn$_invoke$arity$1 (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/nextjournal.clerk.render.hooks.js:321:39)
    at Object.nextjournal$clerk$render$hooks$use_state_with_deps [as use_state_with_deps] (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/nextjournal.clerk.render.hooks.js:345:58)
    at nextjournal$clerk$render$render_result (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/nextjournal.clerk.render.js:470:49)
    at Object.cljs$core$IFn$_invoke$arity$2 (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/nextjournal.clerk.viewer.js:435:117)
    at Function.cljs$core$IFn$_invoke$arity$4 (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/cljs.core.js:13341:10)
    at Function.cljs$core$IFn$_invoke$arity$3 (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/cljs.core.js:13334:34)
    at Function.cljs$core$IFn$_invoke$arity$2 (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/cljs.core.js:13322:34)
    at Function.cljs$core$IFn$_invoke$arity$2 (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/cljs.core.js:13604:34)
    at Object.reagent$impl$component$functional_wrap_render [as functional_wrap_render] (file:///Users/amantini/dev/clerk/public/js/cljs-runtime/reagent.impl.component.js:612:27)

Node.js v18.10.0
 1: 0x102c205fd node::Abort() [/usr/local/bin/node]

I also suspect notebooks using d3-require will always break ssr with:

(build-static-app! {:ssr? true
                      :compile-css? true
                      :resource->url {"/js/viewer.js" "./build/viewer.js"}
                      :index "notebooks/viewers/plotly.clj"}) ;; same for viewers/vega or viewers/tex
Clerk ssr! failed

(node:82220) ExperimentalWarning: Network Imports is an experimental feature. This feature could change at any time
    at emitExperimentalWarning (node:internal/util:227:11)
    at new ESMLoader (node:internal/modules/esm/loader:242:7)
    at node:internal/process/esm_loader:42:19
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/loaders:331:7)
    at nativeModuleRequire (node:internal/bootstrap/loaders:362:14)
    at node:internal/modules/cjs/loader:140:18
    at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/loaders:331:7)
    at nativeModuleRequire (node:internal/bootstrap/loaders:362:14)
    at initializeCJSLoader (node:internal/process/pre_execution:536:21)
    at prepareMainThreadExecution (node:internal/process/pre_execution:100:3)
(node:82220) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
    at emitExperimentalWarning (node:internal/util:227:11)
    at fetch (node:internal/process/pre_execution:215:5)
    at D (file:///Users/amantini/dev/clerk/build/viewer.js:1904:437)
    at file:///Users/amantini/dev/clerk/build/viewer.js:1909:386
    at file:///Users/amantini/dev/clerk/build/viewer.js:1905:512
    at Function.ac (file:///Users/amantini/dev/clerk/build/viewer.js:1906:99)
    at Mg (file:///Users/amantini/dev/clerk/build/viewer.js:2249:16)
    at lh.h (file:///Users/amantini/dev/clerk/build/viewer.js:3152:121)
    at file:///Users/amantini/dev/clerk/build/viewer.js:2467:86
    at Object.cc [as useMemo] (file:///Users/amantini/dev/clerk/build/viewer.js:2063:266)
file:///Users/amantini/dev/clerk/build/viewer.js:1905
nb.redirected&&!U.has(nb.url)&&U.set(nb.url,eb);return nb.json()}));return eb}function v(Ya){function eb(Jb){if("string"!==typeof Jb)return Jb;let Qb=dc.get(Jb);Qb||dc.set(Jb,Qb=new Promise((Aa,E)=>{const N=document.createElement("script");N.onload=()=>{try{Aa(W.pop()(nb(Jb)))}catch(ia){E(new Ta("invalid module"))}N.remove()};N.onerror=()=>{E(new Ta("unable to load module"));N.remove()};N.async=!0;N.src=Jb;window.define=T;document.head.appendChild(N)}));return Qb}function nb(Jb){return Qb=>Promise.resolve(Ya(Qb,
                                                                                                                                                                                                               ^

ReferenceError: document is not defined
    at file:///Users/amantini/dev/clerk/build/viewer.js:1905:208
    at new Promise (<anonymous>)
    at eb (file:///Users/amantini/dev/clerk/build/viewer.js:1905:179)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v18.10.0

@zampino zampino marked this pull request as ready for review January 31, 2023 14:53
@mk mk changed the title SSR Improvements Server-Side-Rendering Improvements Jan 31, 2023
@mk mk merged commit d387037 into main Jan 31, 2023
@mk mk deleted the fix-ssr branch January 31, 2023 16:30
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.

2 participants