Skip to content

Conversation

@anthonybailey
Copy link
Collaborator

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

  • Local with netlify serve: Returns Deno 2.2.4, window does not exist
  • Production: Will reveal actual Deno version and window object status

Endpoint

/api/deno-version - Returns JSON with:

  • Deno version details
  • Window object existence
  • Window.location availability

This is a temporary diagnostic tool for debugging purposes.

Pato-desu and others added 10 commits November 6, 2025 20:40
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)
@netlify
Copy link

netlify bot commented Nov 12, 2025

Deploy Preview for pauseai ready!

Name Link
🔨 Latest commit 5c21cbd
🔍 Latest deploy log https://app.netlify.com/projects/pauseai/deploys/6917e0e82fd32c00081281c6
😎 Deploy Preview https://deploy-preview-544--pauseai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 50 (🟢 up 4 from production)
Accessibility: 89 (no change from production)
Best Practices: 100 (no change from production)
SEO: 99 (🟢 up 1 from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Anthony Bailey added 3 commits November 12, 2025 19:16
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
@Wituareard
Copy link
Collaborator

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.

Anthony Bailey added 2 commits November 13, 2025 13:38
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.
@anthonybailey
Copy link
Collaborator Author

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.

@Wituareard
Copy link
Collaborator

Wituareard commented Nov 13, 2025

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.

@Wituareard
Copy link
Collaborator

Wituareard commented Nov 13, 2025

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]>
@anthonybailey
Copy link
Collaborator Author

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]>
@Wituareard
Copy link
Collaborator

Sounds good to me, didn't think of that

@Wituareard
Copy link
Collaborator

Can we close this now that the fix has been deployed?

anthonybailey pushed a commit that referenced this pull request Nov 15, 2025
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
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.

4 participants