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

Fix tribute related bug #2647

Merged
merged 2 commits into from
Aug 1, 2024
Merged

Fix tribute related bug #2647

merged 2 commits into from
Aug 1, 2024

Conversation

SleeplessOne1917
Copy link
Member

Description

A recent change caused the frontend build to crash with this error:

lemmy-ui-1  | Node.js v20.16.0
lemmy-ui-1  | /app/node_modules/.pnpm/[email protected]/node_modules/tributejs/dist/tribute.js:98
lemmy-ui-1  |   if (window && typeof window.CustomEvent !== "function") {
lemmy-ui-1  |   ^
lemmy-ui-1  | 
lemmy-ui-1  | ReferenceError: window is not defined
lemmy-ui-1  |     at /app/node_modules/.pnpm/[email protected]/node_modules/tributejs/dist/tribute.js:98:3
lemmy-ui-1  |     at /app/node_modules/.pnpm/[email protected]/node_modules/tributejs/dist/tribute.js:2:83
lemmy-ui-1  |     at Object.<anonymous> (/app/node_modules/.pnpm/[email protected]/node_modules/tributejs/dist/tribute.js:5:2)
lemmy-ui-1  |     at Module._compile (node:internal/modules/cjs/loader:1358:14)
lemmy-ui-1  |     at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
lemmy-ui-1  |     at Module.load (node:internal/modules/cjs/loader:1208:32)
lemmy-ui-1  |     at Module._load (node:internal/modules/cjs/loader:1024:12)
lemmy-ui-1  |     at Module.require (node:internal/modules/cjs/loader:1233:19)
lemmy-ui-1  |     at require (node:internal/modules/helpers:179:18)
lemmy-ui-1  |     at Object.tributejs (/app/dist/js/server.js:4103:18)

This change fixes the issue by only importing tributejs when the app is being run in the browser.

package.json Outdated
@@ -60,7 +60,7 @@
"inferno-router": "^8.2.3",
"inferno-server": "^8.2.3",
"jwt-decode": "^4.0.0",
"lemmy-js-client": "0.19.4",
"lemmy-js-client": "0.20.0-alpha.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is causing the error.

Copy link
Member Author

@SleeplessOne1917 SleeplessOne1917 Aug 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to run the app just fine after making the change to markdown.ts.

Edit: This caused an unrelated error to the one I'm fixing. I rolled it back to 0.19.4.

if (isBrowser()) {
Tribute = await import("tributejs");
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might just need to add an exception for the require rule, because I don't see any other way around it. Tribute should be smart enough to null check the window object for SSR apps, but it doesn't.

@dessalines dessalines merged commit bee4395 into main Aug 1, 2024
2 checks passed
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.

2 participants