-
-
Notifications
You must be signed in to change notification settings - Fork 60
Diagnose edge function Deno version #544
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
Conversation
Testing first-request behavior on cold start
- Creates /api/deno-version endpoint configured for edge runtime - Reports Deno version, window object status, and window.location availability - Will help identify differences between local (Deno 2.2.4) and production environments - Related to investigation of 500 errors on dynamic routes (#538, #540)
✅ Deploy Preview for pauseai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
File was used for local testing but triggers ESLint 'Deno is not defined' error in CI
- Add inspection of Deno object properties - Check navigator.userAgent and related properties - Inspect version property descriptor to understand why it returns empty strings - Try multiple approaches to extract runtime version information
Changes isServer detection from build-time constant to runtime check. Problem: - import.meta.env.SSR evaluates to false in edge functions - Bundler optimizes away !isServer guard as dead code - Code tries to access window.location.href in Netlify's Deno runtime - Netlify provides window object but window.location is undefined - Crash: "Cannot read properties of undefined (reading 'href')" Solution: - Use runtime check: typeof window === "undefined" || typeof window.location === "undefined" - Correctly identifies edge functions as server-side (isServer = true) - Prevents bundler from removing the guard - Works in Node.js, Netlify Edge (Deno 2.3.1), and browsers Also removes importRuntimeWithoutVite() workaround - no longer needed with runtime isServer check that works in all contexts. Related: #538, #540
|
isServer has nothing to do with the error, you can check the generated runtime code. And I'm pretty sure that it works correctly because it's replaced at build time by Vite and therefore doesn't depend on the environment. |
Runtime is generated by build process, so static imports fail during ESM scan. Use dynamic import (await import()) in scripts that run before or during build.
Tests whether we can work around paraglide bug by: - Adding window.location if missing - Modifying existing window.location - Deleting or hiding window global Will determine if runtime workaround is possible before committing to post-compilation patching approach.
|
It's more complicated than that, Nils. Paraglide makes a reasonable assumption (in many places across it's compiled runtime) that if window is defined, we are not in a server context, and that window.location.href needs inspected. Some of them are amenable to changing by defining isServer when compiling, but turns out not all: the assumption is hard coded in other places our set up can reach, including one you've seen. Since Netlify's production version of Deno defines a stub window object without a location property in an edge function context, we encounter the 500. We don't really need an edge function for people/, but we would like to use one for localization redirects: it's exactly what edge functions are for, working close to the user rather than having to go through to the server or to serverless functions, both of which are less local (AWS Lambda running in different regions can help, but it isn't a CDN.) I can see how to fix it all, I believe: it's just that quite a few places in the official paraglide release need attention. |
|
Yes I know, but because of that assumption not relying on isServer changing the behavior of isServer won't help (which you have done just before I commented). That's what I was referring to. And I think that the Vite flag is generally more robust than some combination of global variables. |
|
What's your plan for fixing the issues? You could contribute to the paraglide repo I suppose? |
Implements window deletion approach to fix paraglide crash on cold edge function starts. Netlify's Deno 2.3.1 provides partial window object (window exists but window.location undefined) which breaks paraglide-js. Changes: - Add window deletion in hooks.server.ts before paraglide imports - Remove custom isServer override (use paraglide default) - Clarify disableAsyncLocalStorage comment for serverless context The fix detects Netlify's Deno environment and removes the incomplete window stub, making it behave like standard Deno/Node.js where window is properly undefined during SSR. See: notes/20251113-paraglide-edge-function-investigation.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
We had two options. Forking paraglide, fixing it, and depending on that is the very solid dev-correct one. It also means we could submit our patch to paraglide for their consideration, make the future better, etc. But in order to make the near future much better, we have an easier trick: on the way into edge functions, delete the weird Netlify Deno window object whose only impact for us is to break paraglide. (We don't know why they define it. We imagine it may make some other libraries we aren't using work.) |
Add eslint-disable for @typescript-eslint/no-explicit-any rule. This is a diagnostic endpoint for testing edge function environment, so using any types is acceptable for flexibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Sounds good to me, didn't think of that |
|
Can we close this now that the fix has been deployed? |
Re-add People page with AirTable integration Restores the People of PauseAI page, now pulling data from AirTable Members table to showcase staff and key contributors. The page encountered edge function issues with HTTP 500 errors on cold starts due to Netlify's Deno runtime providing a partial window object that broke paraglide-js. This was investigated in #544 and fixed in #548 with a runtime workaround that deletes the incomplete window stub. The fix has been verified working with this page deployment. Note: This page dynamically queries AirTable on each request. It should probably be prerendered (static) in the future to avoid unnecessary load on AirTable, as our key staff don't change frequently. However, it served as a valuable test case for edge function fixes, so merging as-is for now. Original work by @Pato-desu Fixes: #538, #540 Related: #544, #548

Purpose
Adds a diagnostic endpoint to identify the Deno version and window object behavior in production edge functions.
Context
Related to investigation of 500 errors on dynamic routes (#538, #540). Local environment (Deno 2.2.4) behaves differently than production.
Testing
netlify serve: Returns Deno 2.2.4, window does not existEndpoint
/api/deno-version- Returns JSON with:This is a temporary diagnostic tool for debugging purposes.