Code Monkey home page Code Monkey logo

Comments (1)

ztanner avatar ztanner commented on July 19, 2024

Hi @a-k-kord --

As you noted, custom Link interactivity relies on JavaScript, which means React has to hydrate first. This means that even a regular Link click will trigger an MPA navigation until hydration occurs.

Which means that either making a modal with parallel routing is a bad idea

I'm not sure I necessarily agree with this, since I suspect that being able to click the link and view the final page data is better than clicking the link and nothing happening. But nonetheless, this is still something you can control in your app.

One example of a way to deal with this is to disable SSR on the cards so that it waits for hydration, and specify a Loading component to use in the meantime. Under the hood, this makes use of React.lazy and Suspense to render a fallback UI until hydration. eg:

const LazyCardWithLink = dynamic(() => import("../CardWithLink"), {
  ssr: false,
  loading() {
    const id = React.useContext(CardIdContext);

    return (
      <Image
        width={200}
        height={200}
        src={`https://picsum.photos/id/${value}/200/300`}
        alt="alt"
        className="rounded-lg shadow-lg"
        priority
      />
    );
  },
});

This would render the Image and after hydration, it'll swap to CardWithLink which is essentially the image wrapped in a Link. But you could also choose to render a more generic fallback instead.

from next.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.