Next.js Discord

Discord Forum

pls help errors with server side rendering

Unanswered
Cuban Crocodile posted this in #help-forum
Open in Discord
Cuban CrocodileOP
yo so on the console im getting this error:

 A non-serializable value was detected in an action, in the path: `register`. Value: Æ’ register(key) {
    _pStore.dispatch({
      type: _constants__WEBPACK_IMPORTED_MODULE_0__.REGISTER,
      key: key
    });
  } 
Take a look at the logic that dispatched this action:  {type: 'persist/PERSIST', register: Æ’, rehydrate: Æ’}register: Æ’ register(key)rehydrate: Æ’ rehydrate(key, payload, err)type: "persist/PERSIST"[[Prototype]]: Object 
(See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants) 
(To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data) 



and then when im trynna deploy on vercel im getting another error which is:
 ReferenceError: window is not defined
    at Navbar (/vercel/path0/.next/server/app/page.js:1320:5) 


i tried to fix it with useEffect but it just gave me even more errors so yeah idk heres the code:
 const handleResize = () => {
        if (isNotSubmited && window.innerWidth > 1023) {
          dispatch(slide(0))
          enableBodyScroll()
        }
    }

    window.addEventListener('resize', handleResize);

    handleResize(); 



please ask me any additional information or code snippets you need, i would appriciate some help

112 Replies

European sprat
Show the full code of the page it's on and any other relevant files
Cuban CrocodileOP
hey @European sprat and @Asian black bear

i fixed it
it looks nice on pc but on mobile its EXTREMELY SLOW
lmfao idk why it flopped ig
but even on pc you can see on the bottom at the reviews section when you click the button to change, the pic takes like 5 seconds too change
Asian black bear
Tested on iphone pro 13, can comfirm it runs slowly and never fully renders
Asian black bear
Assuming there is some manner of infinite loop, probably accidental recursion in redux
I mean, it is practically a dos
Cuban CrocodileOP
i got no clue but if you wanna check feel free to check the files on github https://github.com/valtonkasami/vivid
these date and time inputs look weird on mobile
and ive set some blue and blurred divs absolute and theyre on the background to make the website with cool gradients so idk maybe theyre making it glitch, since on mobile the divs are invincible
Asian black bear
hmmm I guess it isn't redux
I don't see a specific reason in the code, sorry 😭
    const [ aboutHidden, setAboutHidden ] = useState('')
    const [ aboutHidden2, setAboutHidden2 ] = useState('hidden')
    const [ aboutHidden3, setAboutHidden3 ] = useState('hidden')


Couls be
    const [ openTab, setOpenTab ] = useState(0)
<div className={`${openTab === 2} flex w-full justify-center mt-7 mb-1`}>
 <div onClick={() => {setOpenTab(2)}} className='cursor-pointer py-3 text-[silver] 
@Asian black bear this code kind of looks a mess https://github.com/valtonkasami/vivid/blob/dc50df41a870dc96fab948bee90a849ebe49d162/components/Value.tsx#L62
Cuban CrocodileOP
yee most of my code is a mess, but it works nice on pc, on mobile it starts glitching alot
i think theres too many thinks happening at the same time
ima disable the absolute items in the background for mobiles
@Asian black bear jsx const [ openTab, setOpenTab ] = useState(0)
Cuban CrocodileOP
ill use this for my next projects, thanks
wb the date and time inputs that get out of shape on mobile
it looks fine on pc idkk ima just leave this wtv failed project
Asian black bear
so, I could not test the form on mobile because the site completely froze
it can happen sometimes when JS positions something for example when the document width changes, but what it places makes the document width change again
a very popular way this happens is with the scrollbar appearing and hiding
Safari on iOS is our generation's IE
@Asian black bear Safari on iOS is our generation's IE
Cuban CrocodileOP
ikr i actually thought i liked safari until i started making websites
Asian black bear
hahahahahaahhahahahaha
yeah
Cuban CrocodileOP
yea idk i wont touch nextjs again
i made this with normal react https://anistore.vercel.app/ and its way faster
ig ima need to study nextjs more
Asian black bear
      <div className='flex flex-col gap-y-2 w-full items-stretch'>
      <label className='font-bold text-2xl text-[silver] ' >Hairstyle <span className='text-blue-500 ml-[-2px] font-[1000]'>*</span></label>
      <input type='text' placeholder='Write the Hairstyle' className='bg-[#222222] border-2 h-14 pl-5 hover:border-blue-600 border-[#444444] rounded-lg text-lg' 
      name="hairstyle" id="hairstyle" required onChange={(e) => setHairstyle(e.target.value)} value={hairstyle} />
      </div>
making the flex behavior more defined might help with the safari difference
but idk
AniStore is a nice site
actually your next one is nice tooo, it just needs bugs help
@Asian black bear actually your next one is nice tooo, it just needs bugs help
Cuban CrocodileOP
yea true i mean its nice on pc for now
Asian black bear
did you push an updated version? it works good on my phone now
Cuban CrocodileOP
nah i didnt its the same on my phone
its weird lmao i think its cuz you used the website once so now the phone has it pre-saved or smth like that
Asian black bear
I cannot imagine why, because it was like... totally frozen
Cuban CrocodileOP
ima just watch like a 10 hour advanced project vid on youtube and learn how to do things properly with nextjs and then fix the things
@Asian black bear I cannot imagine why, because it was like... totally frozen
Cuban CrocodileOP
idk ill come back to the project smtimes and fix it but for now ill move on to new projects
thank you for the help
Asian black bear
rewriting it would also be a great learning project
feel free to ping me if you want to do a code review or something
@Asian black bear rewriting it would also be a great learning project
Cuban CrocodileOP
true but i like to not look back and try to build things that are outside of my comfort zone
thats why i fail alot but i also learn alot tbh
@Asian black bear feel free to ping me if you want to do a code review or something
Cuban CrocodileOP
thank you i will
Asian black bear
try doing it, but with this https://headlessui.com/react/disclosure
@Asian black bear try doing it, but with this https://headlessui.com/react/disclosure
Cuban CrocodileOP
oh yea ive heard of this ima try sometimes
ill create a portfolio next
Asian black bear
a lot of React development is about using libraries, and it is definitely good practice to learn how
@Asian black bear a lot of React development is about using libraries, and it is definitely good practice to learn how
Cuban CrocodileOP
yea ive seen some tutorials of it and its cool
yo btw do you think im ready to like apply for junior frontend positions or am i still far off
Asian black bear
oh, the tailwindui.com templates use the Dialog for sidebar drawers
if we were working together on a team I would like to see a bit more dont repeat yourself style reuse of logic, and perhaps a bit more composed usage of react state, but I am not related in any way to hiring or applying for jobs
@Asian black bear oh, the tailwindui.com templates use the Dialog for sidebar drawers
Cuban CrocodileOP
idk what that means but it sounds like a good thing
Asian black bear
it is another component in the library
Asian black bear
like the mobile navigation thing that pops from the side
do you have experience with programming before React or are you jumping right in here?
Cuban CrocodileOP
well 2 months ago i didnt know what css or html was
so ig im jumping
@Cuban Crocodile well 2 months ago i didnt know what css or html was
Asian black bear
So yeah, as we are chatting I think you understand what the code is doing, which makes you a good student
Cuban CrocodileOP
thankss
Asian black bear
sometimes people do tutorials and are like "wow it works" but have no idea
Cuban CrocodileOP
true, i pushed myself really hard to learn how everything works before actually coding
but theres always bugs and new things which you gotta figure out and learn 24/7
Asian black bear
before moving out of the learning phase I would consider doing at least a project with content from a headless CMS like prismic.io, and another one with a UI component library like mui.com
the headlessui.com stuff is good too, but really different from MUI
Cuban CrocodileOP
aight ima do 2 more projects then and use those for each of them
with nextjs cuz i just wanna master it
Asian black bear
yeah, if you are doing React unfortunately Next.js is basically the only real framework for it now
Cuban CrocodileOP
yea true
Asian black bear
I kind of played with remix, but... no
Cuban CrocodileOP
before i started learning i just googled whats the most important things for web development
and nextjs was there so yeah
Asian black bear
I did web development before React and it was pretty brutal
Cuban CrocodileOP
oh damn youre very experienced then, yeah i cant imagine not having states
and redux
like things would be 100 times harder
Asian black bear
redux is kind of... getting a little dated
Cuban CrocodileOP
idk why but i rlly like it cuz like i dont know another way where you can access the same state in multiple different components
access and manipulate it
Asian black bear
like, excellent to get a little taste of, but fundamentally opposed to the philosophy of Next.js /app router
Cuban CrocodileOP
yeah i had to go through 1000 errors to get it to work
Asian black bear
I am obsessed with this library and try to sell to to everyone I talk to: https://jotai.org/
@Asian black bear I am obsessed with this library and try to sell to to everyone I talk to: https://jotai.org/
Cuban CrocodileOP
oh wow it looks extremely impressive
like adobe and tiktok use it
that says it all
Asian black bear
It is a really elegant way to get data into a context to skip over server components without so much boilerplate. The SSR part of it works well with the per-component data fetching in /app pages.
I use this paradigm with it to provide "scopes" https://codesandbox.io/s/elastic-bush-xvn93q
@Asian black bear I use this paradigm with it to provide "scopes" https://codesandbox.io/s/elastic-bush-xvn93q
Cuban CrocodileOP
i like it looks unique ima use it thankss
i never even considered another state management hmm
Asian black bear
figure out how it works 🙂
there is linked list traversal
one other thing you might consdier is doing some of the easy problems on leetcode.com to get a little general programming experience
they look exactly like programming class homework
@Asian black bear figure out how it works 🙂
Cuban CrocodileOP
yess im a fast learner tho i got this, gonna use it for my next project and also use the headlessui
and yea ima watch alotta tutorials to not make any mistakes before i start this project
Asian black bear
cool, and yeah feel free to ping me or send a message
Cuban CrocodileOP
cuz i dont want my portfolio to look bad
@Asian black bear cool, and yeah feel free to ping me or send a message
Cuban CrocodileOP
aight thank you i will