React's New Controversial Override

Поділитися
Вставка
  • Опубліковано 7 тра 2024
  • Oh boy. This again. React is patching another global, this time it's `Date`
    SOURCE
    / 1785691330988986587
    Edited by Ph4se0n3
  • Наука та технологія

КОМЕНТАРІ • 262

  • @StiekemeHenk
    @StiekemeHenk Місяць тому +286

    They should instead add their own date that explicitly specifies server or client date and warn devs in the console if the regular date is used.

    • @dealloc
      @dealloc Місяць тому +4

      That would break backwards compatibility with existing React components/libraries that rely on Date API and is rendered in SSR and hydrated on client.

    • @MaxFunoff
      @MaxFunoff Місяць тому +60

      @@deallocno it won’t, the comment states exactly the opposite of breaking, react team will introduce breaking change with that patch

    • @StiekemeHenk
      @StiekemeHenk Місяць тому +15

      @@dealloc nothing that already exists would be changed or patched, it would be a brand new function to be called.
      The patch they're suggesting would break compatibility as it changes existing behavior. My suggestion would not and would give people the choice to keep using the regular date wherever appropriate but showing a console warning letting the developer know there may be side effects.

    • @foreshadowru
      @foreshadowru Місяць тому +4

      because that will require all libraries that use Date internally to do so as well, or will required you not to use those libraries

    • @ridass.7137
      @ridass.7137 Місяць тому +5

      useDate

  • @SourceOfViews
    @SourceOfViews Місяць тому +232

    Still just a library btw.

    • @follantic
      @follantic Місяць тому

      LOL

    • @SandraWantsCoke
      @SandraWantsCoke Місяць тому +10

      Next.js is just an npm package

    • @gamersma
      @gamersma Місяць тому

      our planet is just a rock suspended in the void

  • @vikingthedude
    @vikingthedude Місяць тому +42

    Next up: We’re patching Math.random()

  • @TazG2000
    @TazG2000 Місяць тому +49

    This is literally the EXACT same reasoning behind the fetch patch. No, it isn't bad just because it's a patch - *it's bad because it's forcing a function to lie.* And this is literally the SAME lie again - an implicitly cached value. The only difference is that instead of returning a cached URL response, we're returning a cached Date output. What is this obsession with forcing return values to support incorrect code, instead of encouraging people to write code that actually manages its own state correctly? If we need a single stable output, then it is the developer's responsibility to retrieve that output once and pass it directly to the other layers that need it - that goes for data fetching, dates, and countless other things. Also, it is up to the developer to decide whether the server OR the client is the source of truth for getting the value - not to assume that one is automatically correct and that they should be in agreement. Stop making functions lie.

    • @riddixdan5572
      @riddixdan5572 Місяць тому

      preach

    • @0dWHOHWb0
      @0dWHOHWb0 Місяць тому

      Yeah, this. I'm mostly a C++ developer, so to me being explicit about things and not having things happen opaquely in the background without my intent or knowledge is a strong preference of mine. Then again, perhaps there is a case to be made for a framework being super basic and offering just a single way to do a thing and then doing a lot of magic in the background to ensure that it's the once and for all best and most optimal way to achieve the desired result. One could also argue that it's only mysterious and opaque and a "lie" if you don't read the documentation. All that said, I personally still prefer for fetch to work the way it does in the browsers, and for me to have the control to implement things the way I see fit. Maybe if you want to have a special cached fetch in the framework, name it something else that reflects its behavior.

    • @TazG2000
      @TazG2000 Місяць тому +3

      ​@@0dWHOHWb0I don't think the designers of this could even make that argument in good faith, because the fact that it's implemented as a patch proves the intent. That is, to deliberately break the behavior of existing external code in order to "fix" their own concerns. In other words, this is breaking the contract of a dependency - which means _also_ breaking the contracts of any other functions that already depends on it - making them lie by extension. _Everything_ using time in the user code will now behave differently than before, depending on whether it happens to be called during the process of serving react content or not. It's a ridiculous band-aid solution to problems that shouldn't exist in the first place, because of flaws in the framework's design (requiring exactly matching view models between client and server, and not being able to pass data easily between layers).

  • @Scereye
    @Scereye Місяць тому +110

    Why does "it suck" that the serverside Date() spits out it's current date and the clientside Date() (if "use client" is stated) spits ITS current date out?
    To me this is expected... No? Like, I get that it's unfortunate and that red equals bad, but... that's just SSR things for you, no...?
    I feel like every potential change to "fix" this just introduces more harm than good. But oh well, we will see...

    • @dealloc
      @dealloc Місяць тому +2

      It is inconsistent with the hydration model. If you only rely purely on SSR vs. CSR then yes, that would be expected to be different results. But here we are dealing with hydration, which means that we expect the same initial state and output on both sides.

    • @Scereye
      @Scereye Місяць тому +21

      ​@@dealloc
      I mean, that's just the expectation of the developer(s) - no...?
      Who is "we" in that case?
      When I first encountered this behaviour (Nuxt.js, but I guess it's the same thing when it comes to this?), it was messy to debug but never did I feel this "issue" needs "fixing"...?
      To me this kind of looks like this wierd obsession of getting rid of red errors by changing the engine under the hood. If the time-delta between SSR and Hydration gets big, why should Date() have the "older" SSR Date on hydration...? At which point is this delta-time an actual dealbreaker? Is it ever?
      I don't know. And i don't really have a Horse in this race, because ultimately I don't really care anyway.
      So... to circle back to my point: The current behaviour makes sense to me even in terms of Hydration. I expect an error. I get an error.

    • @stepans2167
      @stepans2167 Місяць тому +1

      @@Scereyei agree

    • @DubiousNachos
      @DubiousNachos Місяць тому +7

      ​​@@deallocYou expect the client and server to match when you have pure functions and consistent output
      There is nothing pure about the Date constructor - it gives you different results each time you make one (unless you have an initial value you can pass in, which often isn't the case)
      That's the real source of the pain points - React's entire model (which is based on pure functions and snapshot-based state) is not compatible with common non-deterministic values developers would want to use for UIs

    • @Scereye
      @Scereye Місяць тому +10

      ​@@DubiousNachos
      So... this is where we disagree. My point is... I don't expect them to match in this specific case.
      To spell it out more bluntly: If I evaluate the time at different times I expect a mismatch....!?
      And a mismatch results in an error because my SSR stack is expecting a match.
      And that's whats happening, which is - atleast in my mind - the desired behaviour?
      Now is it a bit of a hassle? Yes. Sure... But as I said... that's just SSR things - you should be used to everything beeing a hassle by now.

  • @echobucket
    @echobucket Місяць тому +23

    They should just add a `useDate` hook that you can use that just gives you a date object with the date that was created on the server.

  • @JoeyClover
    @JoeyClover Місяць тому +41

    It's stupid. It solves one of many issues, because you're hydrating with non-idempotent logic. What's next? Are they just going to patch anything that isn't idempotent lmao. SOLVE THE FUNDAMENTAL ISSUE.

  • @StephanHoyer
    @StephanHoyer Місяць тому +47

    Hurray, new footguns to stick in the holes in the old ones shot 🙄

  • @rjmunt
    @rjmunt Місяць тому +86

    Why not make a new function and utilise that on server and client?

    • @foreshadowru
      @foreshadowru Місяць тому +6

      because that will require all libraries that use Date internally to do so as well, or will required you not to use those libraries

    • @JakobTheCoder
      @JakobTheCoder Місяць тому +1

      Same reason as why they patched fetch

    • @ilonachan
      @ilonachan Місяць тому +4

      ​@@foreshadowru then I guess those libraries will just have to use that function internally as well. Better than a library that doesn't know about this and would ABSOLUTELY NOT WORK WITH THIS CHANGE being irreversibly rugpulled, because THAT sounds like a breaking change.

  • @Cool_Goose
    @Cool_Goose Місяць тому +51

    It's a dumb idea.

  • @adaliszk
    @adaliszk Місяць тому +13

    Aren't polyfill by nature only patches when the feature does not exist? While technically does the same patching, it feels different as by design its meant to be not used when possible.

  • @swiclabc
    @swiclabc Місяць тому +29

    Nice, so they are going to break formatting by locale in the browser and timezones...

    • @RT-.
      @RT-. Місяць тому

      I'm sure they've thought of that

  • @ReasonX3
    @ReasonX3 Місяць тому +53

    Polyfills usually have checks that will apply them only if the target functionality is absent. In other words their initialization looks something like this:
    *window.something = checkForSomethingFunctionalitySomehow() ? window.something : somethingPolyfill;*
    At least its definetly how Array and Object static and prototype methods are applied, which makes sense, especially from the point of performance.
    Wouldn't it make more sense to create a separate *React.Date* object that would work the same way as original Date plus hydration fix? Adding *import { Date } from "react"* should be a pretty easy fix and most importantly its very obvious for everyone. I remember when I worked with Angular 1, provided its own function, like setTimeout, that could be injected into components and services via dependency injection.

  • @filipkrawczyk9630
    @filipkrawczyk9630 Місяць тому +8

    Recently, I had the same issue but with Math.random(), and I don't really like the idea of patching js functions, because why only patch Date? Someone could say we should also patch Math.random(), but why stop there? I guess there are so many functions that can behave differently on server and client, so having some of those behave in different ways is weird for me. I think they should come up with some better way of fixing this.

  • @PRonYouTube
    @PRonYouTube Місяць тому +11

    that awkward moment when you record a whole video stanning a decision, only to realize you misread/misinterpreted the original tweet. lmao smh

  • @ShinigamiZone
    @ShinigamiZone Місяць тому +45

    IMO something like this should marked by an eslint plugin...

  • @InfinityN
    @InfinityN Місяць тому +8

    Never patch globals. You don't want different behaviours from environment to environment in what should be standard libraries.

  • @alanhoff89
    @alanhoff89 Місяць тому +14

    Oh boy, can't wait to see all the confusion this will cause across timezones

  • @jasonclements8565
    @jasonclements8565 Місяць тому +6

    The “hydration error” that took me way too long to figure out was just Last Pass adding stuff to my login page.

  • @SourceOfViews
    @SourceOfViews Місяць тому +19

    Tbh it sounds like they only patch it during hydration. So if you write your own js functions that are executed afterwards, you still have the normal Date functionality? Weird I guess, but less bad than I thought.
    Still feel like changing default js behaviour is unnecessarily dangerous

    • @ark_knight
      @ark_knight Місяць тому +1

      This is a valid compromise honestly. Because its hindering a functionality but it should be clearly communicated to devs as well. The patching of fetch was just plain bad idea.

    • @vikingthedude
      @vikingthedude Місяць тому

      Oh so its a transient thing? Damn

  • @Thorax232
    @Thorax232 Місяць тому +10

    This is Vercel making changes to React that they feel is convenient to them. Nothing more. Next is eating React.

    • @naughtiousmaximus7853
      @naughtiousmaximus7853 Місяць тому

      They will literally resurrect Angular with how much they change stuff.

  • @WinterHawke
    @WinterHawke Місяць тому +8

    This seems like a problem with Next's design that they should solve rather than changing Date.

  • @harryhack91
    @harryhack91 Місяць тому +4

    I have a hot take: I think running the same logic *twice* (one on the server and then again on the client) just to render a page is over-engineering. HTMX is the way go (Not to be confused with XHTML), there's no need for a fat front-end framework that takes more than 5 seconds to load (I'm looking at you, Angular). Combine with some nice template engine on the server and you're all set.

  • @infodusha
    @infodusha Місяць тому +5

    The thing about dates is that you dont really need server date but client date

  • @mechaD
    @mechaD Місяць тому +6

    I would think rendering the time should mostly be relative to the browser's time zone. For such use cases it's totally useless to have the date of the SSR reflecting the time zone of the server.
    But hydration errors are a major reason to not use SSR. Translations break the site, password managers break the site, many other browser extensions that change page markup break the site.
    I really would like to have a video that diggs into how to easily deal with all of these situations. Without having to know upfront what kind of Chrome extensions the user will use.

  • @MaxFunoff
    @MaxFunoff Місяць тому +33

    The more we go forward the more Im convinced that JS shouldn’t be on server

    • @GameDevMadeEasy
      @GameDevMadeEasy Місяць тому +2

      I've always felt that way. Too many devs have stockholm syndrome when it comes to JS and have a need to use it for EVERYTHING!!!!

    • @vikingthedude
      @vikingthedude Місяць тому +2

      This would be an issue no matter the language no? Its due to the fact that we have timezones. A true solution would be a one world order

    • @MaxFunoff
      @MaxFunoff Місяць тому +4

      @@vikingthedude with dates yes, but hydration errors is a new being, since the library has shared code between front and back, a less “modern” approach is separation of concerns and just let us do its own thing on client.
      Btw in that note “less modern” we did a full circle from php to separation to php in react/any other meta framework in js.

    • @victor95pc
      @victor95pc Місяць тому +1

      @@MaxFunoff It would be better to avoid SSR, like letting the backend provide the JSON or GraphQL and let the frontend deal with the UI/UX, the only excuse for using SSR is SEO, but does your app need SEO after the logging page? I bet not, the performance argument is a damn lie, if you cache the index.html + chucked your js files for each page + CDN, you would have a super fast app with low resource usage because all the rendering would be done in the client side.
      PS: Even doing that for SEO is quite debatable because the crawler can wait for the React app to render the data, if everything is cached it should be fast

    • @setasan
      @setasan Місяць тому

      ​@@victor95pc agree but i have to admit its much easier to deal with applications with less frontend states and not having to deal with frontend/backend exchanges, things ssr frameworks provide.

  • @azekeprofit
    @azekeprofit Місяць тому +27

    RNG is next

  • @echobucket
    @echobucket Місяць тому +5

    Maybe the problem is trying so hard to make code run on both the client and the server.

    • @vikingthedude
      @vikingthedude Місяць тому +5

      Running non deterministic code twice, trying to get the same result both times. We’re playing with fire here

  • @shadeblackwolf1508
    @shadeblackwolf1508 Місяць тому +3

    There is never a good reason to override a poorly behaved SDK feature, because someone in your tech stack will be dependent on the exact faulty behavior to function correctly. Instead you should raise an MR or ticket against the SDK

  • @arcanernz
    @arcanernz Місяць тому +5

    Hydration error, I think Gatorade would solve that.

  • @almicc
    @almicc Місяць тому +6

    9:18 - What a wild conclusion. I think you have some kind of brain fog. You effectively said that the framework forces you to do something to get around its hydration quirk and then said the solution is for the framework to deliberately implement another quirk to fix it. Maybe the framework should address the root issue, that it should have a better way to separate client and server values that are expected to be different?

  • @luka1790
    @luka1790 Місяць тому +24

    Glad i am not using react and nextjs anymore

    • @programmerjowo
      @programmerjowo Місяць тому +1

      So what do you use now

    • @victor95pc
      @victor95pc Місяць тому +7

      If only use React you wouldn't get these problem, but ppl buy into SSR crap super hard

    • @RaZziaN1
      @RaZziaN1 Місяць тому

      @@victor95pc SSR is really good, just not with javascript. You shouldn't use javascript for this, especially react.

    • @user-fr2fm3ri3w
      @user-fr2fm3ri3w Місяць тому

      @@victor95pc imagine having to use useEffect every other component

    • @DrsHWolfenstein
      @DrsHWolfenstein 8 днів тому

      @@victor95pc Some people need SEO

  • @PHAL__
    @PHAL__ Місяць тому +4

    Now they are just trolling. Why would they think adding more moving parts is always the best solution?
    Can't wait for the Next.js browser to be released by Vercel, with it's own brand new JS Engine.

  • @aaronskriloff
    @aaronskriloff Місяць тому +1

    I’m not currently working on a NextJS project so maybe this was fixed but I would get a hydration error bec I had a chrome extension (I believe LastPass) and once I turned it off the error would go away. I spent so much time looking through my code when it turns out it was just an extension.

  • @justindouglas3659
    @justindouglas3659 Місяць тому +1

    Just curious won't this patch become obsolete once temporals is introduced in js?

  • @AdamPflug
    @AdamPflug 2 дні тому

    One of my most common sources for this kind of error (other than datetime / timezone things) is client-specific stuff. For example if you have any layout code in JS (e.g. to polyfill container queries) or are rendering stuff out of local storage.

  • @theoDSP
    @theoDSP 23 дні тому

    Why does the date function needs to run both on the server and on the client when you use 'use client'? Does it make sense?

  • @John2202W
    @John2202W Місяць тому +1

    I’ve seen a lot of hydration errors caused by invalid HTML (e.g. div inside a p tag). Is there a polyfill for devs knowing what they’re doing?

    • @RT-.
      @RT-. Місяць тому

      What use do you have for this?

  • @tonyb3123
    @tonyb3123 Місяць тому +8

    The situation being "fixed" here is bad code. Initializing a new date to the current time is an effect. We should not trigger effects in render like this

  • @xReDxTuRtLeZx
    @xReDxTuRtLeZx Місяць тому

    as a dev who was learning nextjs, one of my first things was a todo list using a daily list. when i deployed my app to vercel, it was in a different timezone and that led to a whole rabbithole that leads to a similar workaround that you used as passing the date to the client from server, but i opted for only running the date on client side and send that to the server. i dont want to have to run the comparisons there but i just wanted it to work D:

  • @modernkennnern
    @modernkennnern Місяць тому +2

    The thing I love the most about React is the amount of footguns you have access to. Great that they add even more of those!

    • @modernkennnern
      @modernkennnern Місяць тому

      That said, this makes much more sense then the frankly ridiculous fetch thing

    • @codeChuck
      @codeChuck 6 днів тому

      Please, list them all! It would be fun :D
      Like: useEffect for infinite loops, pathing global Date() for confused JS users. What else?

  • @BeheadedKamikaze
    @BeheadedKamikaze Місяць тому +2

    The most common hydration mismatches IMO have been caused by showing / hiding / switching components based on media queries. Your server has to assume some base client dimensions, and then the client will necessarily be different on first render (because not everyone has the same size device). The way we solved it in the past is to use an effect - hard-code the client size to the server value everywhere, including first render on the client, and then when the effect runs (after the client render) you force a re-render at the actual client size. No more hydration error.

    • @nazarshvets7501
      @nazarshvets7501 Місяць тому

      But if you throw away hydration, why hydrate in the first place? Just render the thing instead of hydrating it, bots already got your meta-tags, the rest is for users

    • @BeheadedKamikaze
      @BeheadedKamikaze Місяць тому

      @@nazarshvets7501 because we render mobile-first (initial render targets smallest viewport breakpoint), if the user is mobile then it's faster for them. They're on a lower-powered device than a desktop user so makes sense to help them out a tiny bit.
      Besides, not everything is thrown away, it's only the placement of items that need to change if the layout changes significantly enough that CSS can't effectively handle it.

    • @Lucas-gt8en
      @Lucas-gt8en Місяць тому

      ⁠@@BeheadedKamikazegood solution with solid logic though it feels very silly that y’all are forced to do something like this at all

    • @thekwoka4707
      @thekwoka4707 Місяць тому

      you shouldn't have that handled by js though.
      Thats a job for css

    • @BeheadedKamikaze
      @BeheadedKamikaze Місяць тому

      @@thekwoka4707 sometimes you just need to render a different component depending on your viewport. And other times you need to render the same component, but somewhere else in the DOM. CSS alone can't always do that.

  • @DNAwastaken
    @DNAwastaken Місяць тому

    Is using the “suppressHydrationWarning” prop in React okay when working with dates? If not, how else would you tackle the issue?

  • @sa1_p
    @sa1_p Місяць тому

    I think the main problem with dates is the timezone issue, as Indian i want my dates to be in IST (Indian standard time) and formatted DD/MM/YYYY but implementing that without hydration errors is a headache

  • @jabbruh4785
    @jabbruh4785 Місяць тому +8

    I get alot of hydration errors related to p tags

    • @victor95pc
      @victor95pc Місяць тому

      Move to CSR, it will be solved haha

    • @bruceleeharrison9284
      @bruceleeharrison9284 Місяць тому +6

      We should patch p tags too

    • @lucafelix
      @lucafelix Місяць тому +1

      Probably incorrect HTML, placing divs inside p tags etc...

    • @jabbruh4785
      @jabbruh4785 Місяць тому

      @@lucafelix nah it was with li tags... But maybe I am to stupid... That's at least how I feel haha

    • @la.zanmal.
      @la.zanmal. Місяць тому +3

      After hydration, just p normally, don't tag with it, that's the error.

  • @mequyo2012
    @mequyo2012 Місяць тому

    I get a hydration error when I put a button in a menu from shadcn because the menu itself is basically a button and nested buttons seem to cause that error

  • @mohamedyamani8502
    @mohamedyamani8502 Місяць тому

    an easier way to check what the server has returned is to right click anywhere on the document and choose "view page source", or use the shortcut Ctrl + U

  • @coderjosh5647
    @coderjosh5647 Місяць тому +2

    I was more so hoping that they could also help unify other massive headaches of Date. Such as:
    > new Date("2024-01-01")
    Date Sun Dec 31 2023 19:00:00 GMT-0500 (Eastern Standard Time)
    > new Date("2024/01/01")
    Date Mon Jan 01 2024 00:00:00 GMT-0500 (Eastern Standard Time)
    But well,,, I guess for now, this will just be a dream

  • @shadeblackwolf1508
    @shadeblackwolf1508 Місяць тому

    Question, why does it suck for local time to be calculated where it's most relevant for the user? especially if they live somewhere with poor internet so there may be a minute or two between the local and server times for a page? And how would we display the local date and time in the client's timezone according to the client's machine after this change? Shouldn't date run only once on the client to avoid collision instead to provide the date correctly bound and formatted for the user?

  • @jakeotoole4406
    @jakeotoole4406 Місяць тому +1

    I know this isn't the same topic, but can we please update Date()? How does it not include like all the functionality of a day.js or date.fn yet? The specific nightmare I constantly run into is Date() and associated methods being so hell bent on making the date relative to the user's locale.

    • @mx-dvl
      @mx-dvl Місяць тому

      Look at the Temporal TC39 Proposal ❤

  • @helleye311
    @helleye311 Місяць тому

    On the fence about this. I mean, it seems like it's not that big of a deal if it's only during hydration (I didn't like fetch because it was always there whenever you made a request, this just fixes one issue and then goes away). But I've never had date related hydration errors happen to me. As long as it doesn't mess with anything at runtime I'll get used to it (as in, forget it's an issue in the first place)

  • @johnayling2820
    @johnayling2820 Місяць тому

    How can running the code twice and matching the HTML be more effective than before when we just ran the code on the client and attached it

    • @Lucas-gt8en
      @Lucas-gt8en Місяць тому

      The first version of the page you load is more complete. It’s especially useful for SEO crawlers as they have a limited amount of compute and time. Honestly to me ISR is the least sucky solution for this but what do I know 🤷

  • @samuel-maa
    @samuel-maa Місяць тому +1

    I actually have a big issue with Hydration in my code, I always thought it was just a Nextjs problem....but it turns out that it's an overall React problem

  • @furycorp
    @furycorp Місяць тому +38

    The cycle is so funny how the "brilliant" kids of today resolve the same old solved problems from tech generations past, unwilling to search anything and insistent on putting their own fingerprints on their own solution, stubbornly insisting that the lessons learned from the past don't apply to them because of their genius and unwillingness to read about anything that predates them. Its like pre Y2K is groundhog day over and over and over and oveeerrrrrrrr... Vercel, React (who Vercel has been buying up like crazy and notice all the new BS!?), and so on. The hottest things in tech today are eerily reminiscent of decades ago now.

    • @BeBoBE
      @BeBoBE Місяць тому +6

      Just because something provokes the same feelings in you doesn’t mean it’s the same thing… Nice rant

    • @MadsterV
      @MadsterV Місяць тому +4

      @@BeBoBE it's the same techniques with the same results and pitfalls. Just because you're young doesn't mean old problems don't apply to you

  • @ApprendreSansNecessite
    @ApprendreSansNecessite Місяць тому +5

    I am sorry but this is so stupid. It's called a side-effect and there are means to manage them.

    • @neociber24
      @neociber24 Місяць тому +1

      Like only running the date on the client.

    • @ApprendreSansNecessite
      @ApprendreSansNecessite Місяць тому

      There are many ways to deal with this depending on what you want. new Date().toLocaleString() has 2 dependencies : the current time and the locale. You may want to use the current time of the server, for example to make sure it is in sync with some server-side stuff, but you will most likely want to use the user's locale. Whether you do any of this on the client side or the server side, you must acknowledge that there are 2 dependencies that make this call impure. You may for example get the locale and time zone from the client and render that on the server, it does not matter, but if you make side-effects visible in your code, or even in your type system, you will not be surprised by this kind of behaviour and you will have the luxury to deal with this in a number of ways.
      I heard Effect-TS have a React runtime now. I have no idea what they use it for and if it's compatible with server-side rendering but I would look it up.
      In any case, I would 9 times out of 10 prefer to take control of my side effects rather than depend on some spooky action at a distance by a third party.

  • @yaroslavpanych2067
    @yaroslavpanych2067 Місяць тому +11

    Okay, it sounds like their priblem.
    They are good at inventing tasks for them, that are useless for the world!
    SSR stands for what? SERVER Side Rendering, which is how it was working from the very beginning: we generated HTML fragments based on data available on the server and client side was supposed not to question that html much, just work with it. Reacts philosophy is out of scope here. For me that means, if React has issues with SSR in conceptual level, then it will no be used at all in such setup.

    • @neociber24
      @neociber24 Місяць тому

      This isn't just React but any other framework that needs hydration.
      You can use React just for SSR and ignore all those stuff, but if you need to continue doing things on the client that is other paradigmn

    • @nazarshvets7501
      @nazarshvets7501 Місяць тому

      @@neociber24 Why hydrate when you can just rerender? (you never gonna escape browser extensions which mess with your html)

  • @sowboo
    @sowboo Місяць тому

    Lastpass modifying inputs was causing same hydration issues in my experience. That was a really dumb thing to debug

  • @Chris...S
    @Chris...S Місяць тому +3

    Why are they so adamant to patch something. Their isn't any issue with Date(). It does what it should. Give you a hydration warning so that you as the developer can fix depending on your use case. Stop trying to take the power away from the devs. Any dev that complains needs to learn more about how it works and why it gave that error.

  • @elmikolus
    @elmikolus Місяць тому

    So, as I understood, we want to run impure function on different envs with different states connected to it and we expect that the result must be the same which is obviously impossible and we need to have sicret hack to achive this goal.
    Looks like the same will happen with Math.random.

  • @professormikeoxlong
    @professormikeoxlong Місяць тому

    Couldn't we just exclude date from SSR rendering alltogether

  • @almicc
    @almicc Місяць тому +1

    Seeing this demo where you get a hydration error, I can't help but see this as a problem with React only. Something like a time meant for local display should never create an error, the best it could be is a warning to the developer that they might have written a bug if they intended the client to display the 'server' time but are actually displaying the 'client' time. This would be corrected by specifying a timezone explicitly, and then React should never do validation on the results of Date objects. It should be precisely the same thing as having a Math.random() call that runs on server and client, React should give a warning and then explain how they want you to be explicit on the intended behavior.

  • @BryanLeewood
    @BryanLeewood Місяць тому

    Regardless of my thoughts on Date, you did a fantastic job explaining hydration errors here that I think is super helpful and educational.

  • @user-qe2nv5dg2x
    @user-qe2nv5dg2x 27 днів тому

    the first time i had one, the time it took me to understand it was kinda of annoying,
    i understood it because i was commenting out components one by one to figure out where this happened.

  • @e_tas_
    @e_tas_ Місяць тому

    This video is also one of the best explanations for hydration errors I've ever seen

  • @Pharoxx105
    @Pharoxx105 Місяць тому

    I really think the resumeability model is the right way forward. In my opinion running the same code on the backend and again in the frontend just to correctly attach event handlers is a bad idea. Makes the mental model more complex for no good reason

  • @walber33
    @walber33 Місяць тому

    Didn't know about resumability, but it seems more logical to me, why would you regenerate the HTML just to link things, ids are exactly for that.

  • @todpale
    @todpale Місяць тому

    If you test your date function win new Date() inside in a unit test, you can get a failed scenario (80% of cases, I guess). Milliseconds...

  • @SuperElephant
    @SuperElephant Місяць тому

    The tech debt behind is unimaginably deep and unrecoverable.

  • @brendonovich
    @brendonovich Місяць тому +3

    Personally not a fan of the fetch patch - React and Solid Router's dedicated cache functions are better imo - but I could get onboard with this one.
    This date patch would _only_ happen on the client during hydration, in all other component executions Date would behave normally, so I'm guessing it'd be possible for a server time to be hydrated, before being quickly replaced by a different time generated on the client in a subsequent rerender.
    I'd say that's kinda the expected behaviour - if you server render a Date React should at least be able to hydrate that part properly, whether it gets replaced by a client-generated date in the future is your problem. At least the patch would be for internal behaviour that happens during a process you don't get control of - unlike the fetch patch which alters a user-facing API.
    Solid Router kinda does a similar thing with createAsync and Promise, where during hydration Promise will be patched to literally just be Promise.resolve, so that createAsync can re-run and hydrate without re-executing queries on the client after they've been done on the server.

    • @Luxalpa
      @Luxalpa Місяць тому

      Yes, this works for Promise and in principle this could work for Date too, but it won't work in practice because both client and server Date's are valid, so no matter which one you use as "source of truth" there will always be the other one that creates a conflict. In this case the Date that comes in via hydration will be completely unexpected and inconsistent with all successive dates that are created on the client.

  • @VeXii12
    @VeXii12 Місяць тому

    So react is going to patch Date because Browsers don't give correct headers? Both Chrome and Firefox always sets "Accept-Language" to "en-US" even though my system is set to "en_DK.UTF-8"
    why not make the browsers respect the system settings and report that in the hearders?

  • @Luxalpa
    @Luxalpa Місяць тому

    As a leptos user, I am an expert in Hydration Errors!

  • @SirLightfire
    @SirLightfire Місяць тому

    I feel like we should enforce language versioning in the browser
    have the client script specify which version it's targeting, and have the browser adjust it's behavior for backwards compatibility
    rather than baking backwards compatibility into JS and living with that baggage

  • @justingolden87
    @justingolden87 Місяць тому

    Educational for low/medium skilled React devs / web devs in general using a js framework!

  • @blenderpanzi
    @blenderpanzi Місяць тому +1

    Patching things is very problematic. I just switched from jest to vitest, because when I run my code via jest `error instanceof Error` is always false and so all my error handling code breaks. They somehow patch all globals for some reason? I stopped investigating, I don't have the energy for that. vitest on the other hand segmentation faults all over the place unless I use --pool=forks. Well, at least I could make it work. Ugh. Why is it all so horrible in JavaScript land?

    • @vikingthedude
      @vikingthedude Місяць тому +3

      I hate the way jest patches globals. It takes away all power from the programmer, you’re at the mercy of jest. I like how vitest makes you import stuff instead of giving you globals

    • @blenderpanzi
      @blenderpanzi Місяць тому +1

      @@vikingthedude Exactly!

  • @Adowrath
    @Adowrath Місяць тому

    The difference to polyfills is, though: If the polyfill isn't necessary on a client, it won't be polyfilled. Patching *alway* changes things.

  • @griffadev
    @griffadev Місяць тому

    You should read Artem Zakharchenko article on Why Patching Globals Is Harmful could be good balance

  • @nazarshvets7501
    @nazarshvets7501 Місяць тому

    Next vid: we droping hydration because this browsers extentions are insane
    tbh: why spend time on hydration, when you know you would rerender anyway (dates, random, media-queries etc)?

  • @PhilipAlexanderHassialis
    @PhilipAlexanderHassialis Місяць тому +16

    Or (hear me out), client components could be only that: components that run on the client. Exclusively. Why does the "use client" component run on the server? Why does it have to? If I wanted server component, then I wouldn't place a "use client" directive. What kind of abnormal behaviour is this?

    • @dreamecho100
      @dreamecho100 Місяць тому +1

      Doesn't Next.js do these to send the HTML and CSS first and then hydrate it?
      And I think you can achieve a client only component with dynamic or lazy components

    • @dealloc
      @dealloc Місяць тому +1

      To optimize for first contentful paint and prevent sudden pop-in which is most common use-cases. For streaming HTML and selective hydration you can wrap client components in a Suspense.

    • @neociber24
      @neociber24 Місяць тому +1

      That's a missunderstanding.
      Client component are just componentes that are hydrated.

    • @neociber24
      @neociber24 Місяць тому

      If you don't want components that run on server use "dynamic" or don't use a SSR framework.

    • @PhilipAlexanderHassialis
      @PhilipAlexanderHassialis Місяць тому +1

      @@neociber24 Well, I like the idea of having a built in routing system and an environment that is a bit opinionated, plus a "complete package" on how to take the whole .next directory, dockerize it and slam it in my infra. What I *don't* like is the fact that it has to SSR everything.
      Once again, "old" Next was very simple to that: you have "getServerrSideProps", it's SSR, you don't, it's classic create-react-app. I don't say it's better or worse. I say that the behaviour was *simple* and easy to work with.
      They should accommodate for these kind of scenarios too - instead the whole React ecosystem is dragged into this. Sigh.

  • @medbenbrahim3246
    @medbenbrahim3246 Місяць тому +1

    They are so invested in ssr rehydration, that nothing seems wrong to them anymore

  • @MadsterV
    @MadsterV Місяць тому

    couldn't they just lint converting dates to string in SSR and before hydration?

    • @MadsterV
      @MadsterV Місяць тому

      I mean the actual problem is mishandling of data

  • @SonAyoD
    @SonAyoD Місяць тому

    Stuff like this makes me want to learn quik

  • @AlexanderBorshak
    @AlexanderBorshak Місяць тому +1

    The React team is turning into a source of memes...

  • @KangoV
    @KangoV Місяць тому +1

    As a Java dev looking in, I've come to the realisation on how much of a cluster f$ck the JS world is! I feel blessed that I've managed to avoid it for 32 years!

    • @user-fr2fm3ri3w
      @user-fr2fm3ri3w Місяць тому +2

      public static void main string args

    • @naughtiousmaximus7853
      @naughtiousmaximus7853 Місяць тому

      @@user-fr2fm3ri3w tab + psvm

    • @KangoV
      @KangoV Місяць тому

      @@user-fr2fm3ri3w You can now do "void main() {}". Do keep up :)

  • @pacifico4999
    @pacifico4999 Місяць тому

    React is its own meta language at this point

  • @05xpeter
    @05xpeter Місяць тому

    As developer of react app which is only using client side rendered components and quite allot of date.now and timedeltas, I really hope this patch does not have any effect on my code.

  • @alexanderharding
    @alexanderharding Місяць тому

    Create a higher level date API for SSR. Monkey patching date is not necessary.

  • @vommir.
    @vommir. Місяць тому

    That's good, I ran into this issue last week with date and used dayjs to solve it but glad to know now it will be right out of the box.

  • @neociber24
    @neociber24 Місяць тому

    Your date on the client should not depend on the date the server returned but I still don't know how it will be implemented.
    I don't care about patches if are explicit but trying make Date work different doesn't sounds good, we should just live with the problem and existent solutions

  • @fricze
    @fricze Місяць тому

    Sweet mother of god. That's insane. React is going crazier and crazier.

  • @bitmasked
    @bitmasked Місяць тому

    The React team needs to invest in a thesaurus.

  • @user-zc6dn9ms2l
    @user-zc6dn9ms2l Місяць тому

    standards ? Does this mean : Binary code patch

  • @thekwoka4707
    @thekwoka4707 Місяць тому

    Easy fix:
    Stop doing hydration
    Do resumability
    Qwik did it already.

  • @StabilDEV
    @StabilDEV Місяць тому

    Dates should only ever be client rendered

  • @TheUnknownFactor
    @TheUnknownFactor Місяць тому

    This will cause dumb/unexpected shit with isr / pre-rendering

  • @bertrodgers2420
    @bertrodgers2420 Місяць тому

    So are people still going to push the idea that react is just a framework?

  • @FeLiNe418
    @FeLiNe418 Місяць тому +1

    Just don't use js on the backend

  • @BenKingUK
    @BenKingUK Місяць тому

    Just fix hydration.

  • @Abhidjt
    @Abhidjt Місяць тому

    Damn.

  • @Life4YourGames
    @Life4YourGames Місяць тому

    In my opinion, having this server-defined behavior on the client is not acceptable. Even when it's limited to hydration.
    This approach would need similar changes for ANY value that might be serialized differently on the client than on the server (so every localizable value basically).
    A way better approach would see a way to make the Hydration algorithm sensitive to these outputs and ignore / accept the differences in serialization output in these places.
    Use data-Attributes, marker comments, whatever floats your boat. But do not monkey patch serialization and localization features on the client to force them to output the same as the server.
    This is a rabbit hole we do not want to go into.

  • @vaibhavpathak6721
    @vaibhavpathak6721 Місяць тому

    It's soo dumb, yk what's the best way to fix this issue is just use server side rendering.