fix: Resolve bulk downloads, PostHog crash, and missing file UX - #544
Rithish-2914 wants to merge 4 commits into
Conversation
4d54012 to
6223596
Compare
6223596 to
48bfb89
Compare
| } | ||
| posthogClient ??= new PostHog(token, { | ||
|
|
||
| const phModule = require("posthog-node"); |
There was a problem hiding this comment.
it gets build on every upload or an api call...may be do something like If(posthogClient)return it ?
There was a problem hiding this comment.
Great catch brooooo You're totally right, it was hitting that require on every single upload(i didnt see tht)
I just pushed a commit that adds an early return at the very top so it caches the client immediately after the first call.
|
|
||
| useEffect(() => { | ||
| let isMounted = true; | ||
| fetch(url, { method: "HEAD" }) |
There was a problem hiding this comment.
since we already handle that error, still do we need this ? will it delay the paper fetching by any chance?
There was a problem hiding this comment.
We actually still need the HEAD request! The issue is that the PDF library's built-in error handler completely fails when GCS returns a 404 (because GCS returns an XML page, and the viewer gets stuck trying to parse it as a PDF, causing an infinite loading spinner). The HEAD request is just a tiny pre-flight check that catches the 404 instantly before the viewer can hang.
And don't worry about delays! Because it's a HEAD request, it only grabs a few bytes of server headers without downloading the actual PDF payload. It takes less than 50ms and happens in the background before the heavy WASM engine even initializes, so there's zero noticeable delay in paper fetching so no worries
| } catch (error) { | ||
| console.error("Download failed:", error); | ||
| console.error("Download failed (File missing or network error):", error); | ||
| toast.error("This paper is no longer available on the server."); |
There was a problem hiding this comment.
make sure this error is shown only for a particular error response status, else even for a no internet situation, this might be shown to the uses..kind of misleading
There was a problem hiding this comment.
Good point! If their internet drops, they shouldn't see the "paper is missing" error. I just updated the catch block to check navigator.onLine. Now, if it's an actual network failure, it gives a specific "You are offline" toast instead!
Heellooo guys, this PR squashes multiple bugs and drastically improves the UX when interacting with "ghost" papers (papers where the file was deleted from Google Cloud Storage but the record still exists in the DB):
.zipextension. It now correctly saves as a standard.zipfile!posthog-nodelibrary during production builds, throwing aPostHog is not a constructorerror on uploads. I added a bulletproof workaround using a dynamic namespace import to ensure analytics track cleanly.HEADcheck. If the file is missing, it immediately aborts the PDF engine and displays a clean "Paper Not Found" UI overlay.