Comments (8)
Since I have verified that using dynamic imports of the components works, I believe we can consider this matter resolved. Thank you, @echarles, for your assistance!
from jupyter-ui.
The issue is coming from the lumino package domutils which access the window.navigator. Currenlty the "use client"
at the top of the page.tsx does not seem to be enough for next.js to not compile on server that part.
I have tried the following with success
"use client"
import { useState, useEffect } from 'react';
export default function Home() {
const [Jupyter, setJupyter] = useState<any>(undefined);
const [Notebook, setNotebook] = useState<any>(undefined);
useEffect(() => {
// Keep the import in this useEffect to avoid Lumino domutils breaking Next.js server compilation.
const { Jupyter } = require('@datalayer/jupyter-react');
const { Notebook } = require('@datalayer/jupyter-react');
setJupyter(Jupyter);
setNotebook(Notebook);
}, []);
return (
Jupyter && Notebook
?
<>
<h1>Jupyter React in Next.js</h1>
<Jupyter
jupyterServerHttpUrl="https://oss.datalayer.tech/api/jupyter"
jupyterServerWsUrl="wss://oss.datalayer.tech/api/jupyter"
jupyterToken="60c1661cc408f978c309d04157af55c9588ff9557c9380e4fb50785750703da6"
>
<Notebook
path="ipywidgets.ipynb"
uid="notebook-nextjs-1"
/>
</Jupyter>
</>
:
<></>
)
}
```
from jupyter-ui.
Docusaurus build has similar constraints (not build on server the jupyterlab/lumino parts). With docusaurus, you can use the BrowserOnly
component. I don't know next.js well, so any feedback on how to implement similar behavior for next.js will be much appreciated. Thx!
jupyter-ui/packages/docusaurus-plugin/src/theme/JupyterCell.tsx
Lines 7 to 24 in 092b1fe
from jupyter-ui.
Alright, I understand. Now that you've explained this, one workaround is to include the following line of code in your layout.tsx file of your Next.js app to disable server-side rendering (SSR). This solution seems to be effective and allows for a successful build. However, by applying this at the layout level, SSR will be disabled for the entire app. I tried to disable SSR for the specific page where Jupyter and Notebook is imported but not working. We may need to explore alternative approaches to make it work.
export const dynamic = 'force-dynamic'
from jupyter-ui.
Will try that, otherwise I have moved the code outside of the page and it works. Will push options.
from jupyter-ui.
By setting export const dynamic = 'force-dynamic'
in layout, still prompt the error, I use it locally nextjs 14.1.3
from jupyter-ui.
By setting export const dynamic = 'force-dynamic' in layout, still prompt the error, I use it locally nextjs 14.1.3
@chenjpu Have you set 'use client
? this is often the cause of the issues.
https://github.com/datalayer/jupyter-ui/blob/main/examples/next-js/src/app/page.tsx#L7
from jupyter-ui.
@echarles Thanks, I have found the cause of the problem
from jupyter-ui.
Related Issues (20)
- Upgrading to `@jupyterlite/server(-extension)` 0.2.3 breaks jupyter ui lite
- Jupyter Hub support HOT 6
- Preinstalling Libraries when using a notebook component rather than JupyterLabs component HOT 1
- Right click on the JupyterLabApp component makes the layout to shift up and open bottom panel HOT 4
- Bug on saving a file HOT 1
- Creating Custom Toolbar | Sidebar HOT 2
- Issue with Vite Example HOT 6
- Markdown collapsing instead of rendering. HOT 1
- Cell height is off by as much as 30+x HOT 3
- Typescript Version Issue HOT 1
- Issue with nextjsExample HOT 1
- Create the Jupyter session or server on-demand HOT 2
- Save from notebookActions is not working anymore HOT 3
- Global CSS cannot be imported from within node_modules. HOT 2
- Error: widget model not found HOT 1
- How to configure adding Teradata AI Unlimited custom renderer and sqlhighlighter HOT 7
- Autocomplete does not work in notebook in examples HOT 3
- Use `oss.datalayer.run/api/jupyter-server` (instead of `oss.datalayer.tech/api/jupyter`) for free cloud kernels
- Tab key does not invoke autocomplete on a new cell until the new cell is re-selected HOT 1
- Changing notebook path loads new file but shift-enter doesn't work HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jupyter-ui.