How To Deal With "Window Is Not Defined" In SvelteKit

  Рет қаралды 4,357

Joy of Code

Joy of Code

Күн бұрын

Пікірлер: 23
@GrizhlieCodes
@GrizhlieCodes 2 жыл бұрын
Well darn, I did not know about the (browser) bit. That makes my life simpler, cheers.
@JoyofCodeDev
@JoyofCodeDev 2 жыл бұрын
You're welcome! 💪
@tithos
@tithos Жыл бұрын
Same here. I have seen it, but it never "clicked"
@pm1234
@pm1234 2 жыл бұрын
Is it a PNG mask in OBS Studio you use or something else?
@JoyofCodeDev
@JoyofCodeDev 2 жыл бұрын
Yeah! 😄
@carlos-hernandez.
@carlos-hernandez. 4 ай бұрын
Excelent!
@senseicodes
@senseicodes 2 жыл бұрын
Hey what about a UI library that uses the window object and you have to import its js file like so; (import 'uikit') or import 'uikit.min.js'
@JoyofCodeDev
@JoyofCodeDev 2 жыл бұрын
You can use a dynamic import or disable SSR for the page: kit.svelte.dev/docs/page-options#ssr.
@senseicodes
@senseicodes 2 жыл бұрын
Thank you
@tithos
@tithos Жыл бұрын
This inspired me to fix a bug I have on my tic-tac-toe app I made with sveltekit. I had scooping issues trying to use onMount. I this browser with help. 🤞🏼
@leelonghui
@leelonghui Жыл бұрын
When to use onMount and browser?
@JoyofCodeDev
@JoyofCodeDev Жыл бұрын
Most of the time you're going to use `onMount` to run some logic and `browser` inside a variable or conditional block.
@qwikdeveloper1776
@qwikdeveloper1776 Жыл бұрын
Have you ever been able to make libraries like Lokomotiv or Lenis work with Svelte?
@JoyofCodeDev
@JoyofCodeDev Жыл бұрын
Is this particular to those libraries or would a video on how to use third party libraries with Svelte help?
@qwikdeveloper1776
@qwikdeveloper1776 Жыл бұрын
@@JoyofCodeDev so first of all thanks so much for replying, you're really doing gods work with your videos. For me svelte is close to the perfect framework except for the lack of a good smooth scrolling library. If you see those fancy award winning websites they almost all have scrolling effects. And the scrollY trick doesn't work properly on some browsers due to performance issues. I don't know what you would suggest. I personally haven't been able to integrate libraries like Lokomotiv or lenis. Thanks for your feedback
@JoyofCodeDev
@JoyofCodeDev Жыл бұрын
@@qwikdeveloper1776 I would use GSAP: greensock.com/scrollsmoother/.
@qwikdeveloper1776
@qwikdeveloper1776 Жыл бұрын
@@JoyofCodeDev The problem with GSAP is that it's not opensource and requires a license. Scrollsmoother alone costs at least $150+ per year.
@hoyakim4280
@hoyakim4280 Жыл бұрын
I've resolved this problem by adding "export const ssr = false;" in +layout.js because my application completely separated client and server projects.
@JoyofCodeDev
@JoyofCodeDev Жыл бұрын
That also works! 😄
@shiytp
@shiytp 2 жыл бұрын
if (typeof window !== 'undefined') { return `😏` }
@JoyofCodeDev
@JoyofCodeDev 2 жыл бұрын
Your code could run in an environment where `window` exists like Deno, so you have to use `self`.
Stop Using Types In SvelteKit
5:28
Joy of Code
Рет қаралды 15 М.
Using The Svelte Context API With Stores
10:17
Joy of Code
Рет қаралды 14 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Mom Hack for Cooking Solo with a Little One! 🍳👶
00:15
5-Minute Crafts HOUSE
Рет қаралды 23 МЛН
Use Svelte 5 Snippets To Reuse Markup Without Creating Components
17:41
Next.js Error: window is not defined (FIXED)
5:14
ByteGrad
Рет қаралды 9 М.
Protect SvelteKit Routes with Hooks
21:10
Huntabyte
Рет қаралды 60 М.
Understand How Data Flows Through SvelteKit
25:59
Joy of Code
Рет қаралды 20 М.
Python laid waste to my C++!
17:18
Sheafification of G
Рет қаралды 120 М.
SvelteKit Group Layouts Give You Absolute Control Over Layouts
13:20
Master The Svelte Context API
18:07
Joy of Code
Рет қаралды 8 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 492 М.
Using JavaScript Libraries With Svelte Is Easy
17:37
Joy of Code
Рет қаралды 13 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН