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

Lazy.eval - Window is Not Defined Error #988

Open
carleighroche opened this issue Jul 29, 2024 · 2 comments
Open

Lazy.eval - Window is Not Defined Error #988

carleighroche opened this issue Jul 29, 2024 · 2 comments

Comments

@carleighroche
Copy link

Although the data is coming through and the page is rendering fine, I am seeing a window is not defined error. Has anyone seen this / know the source of the issue?

⨯ Internal error: ReferenceError: window is not defined
    at Lazy.eval [as fn] (./node_modules/@glideapps/glide-data-grid/dist/esm/common/browser-detect.js:25:73)
    at get value [as value] (./node_modules/@glideapps/glide-data-grid/dist/esm/common/browser-detect.js:14:45)
    at realizeKeybinds (./node_modules/@glideapps/glide-data-grid/dist/esm/data-editor/data-editor-keybindings.js:67:87)
    at eval (./node_modules/@glideapps/glide-data-grid/dist/esm/data-editor/data-editor-keybindings.js:129:16)
    

I am running this app on NextJS 14 in a client component.

What is a good place to start looking for the source of the issue?

@mengxi-ream
Copy link

I also have this issue

@mengxi-ream
Copy link

mengxi-ream commented Dec 26, 2024

This error occurs because Next.js attempts to perform server-side rendering (SSR) by default, even for components marked with "use client". During SSR, the window object is not available since it's a browser-specific API.

To resolve this issue with @glideapps/glide-data-grid, the temporary solution is :

  1. Use dynamic import for the DataEditor component
  2. Disable SSR for this specific component

like

const DataEditor = dynamic(
  () => import("@glideapps/glide-data-grid").then((mod) => mod.DataEditor),
  { ssr: false },
);

But the proper solution should not use window during ssr time,

for example

// this code will run on server and client
const Component = () => {
  // on server, it will throw the error because we don't have window
  const windowWidth = window.innerWidth;  
  return <div>Width: {windowWidth}</div>;
}
const Component = () => {
  // useEffect will only run in client
  const [windowWidth, setWindowWidth] = useState(0);
  useEffect(() => {
    setWindowWidth(window.innerWidth);
  }, []);
}

This requires us to improve the source code

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