Git Product home page Git Product logo

Comments (18)

JohnAllen avatar JohnAllen commented on May 5, 2024 1

LOL what makes you think that? Hahahahah @moinulmoin

from examples.

balazsorban44 avatar balazsorban44 commented on May 5, 2024 1

To whom it may concern, please keep the discussion to the point!

from examples.

StitiFatah avatar StitiFatah commented on May 5, 2024 1

Hi again, the issue is solved for me and everything is working with fallback:true and even with CSR when using the last canary version 12.0.8-canary.20. I closed the issue here vercel/next.js#32446

@moinulmoin

from examples.

JohnAllen avatar JohnAllen commented on May 5, 2024

I can't solve it without having the code. I know what it is about but not sure exactly where the error is.

from examples.

moinulmoin avatar moinulmoin commented on May 5, 2024

I just simply followed the steps which are in readme.md then I am getting this error. Could you please give a check now by following steps? thanks

from examples.

jonspark avatar jonspark commented on May 5, 2024

I'm coming up with the same issue with a fresh project based on the example. This line is the only reference to a href="/"

There's a similar issue if you visit the About page but the value is /about.

NextJS error message stating: Unhandled runtime error - Error: The provided `as` value (/about) is incompatible with the `href` value (/_sites/[site]/about). Read more: https://nextjs.org/docs/messages/incompatible-href-as

from examples.

StitiFatah avatar StitiFatah commented on May 5, 2024

Same here, but only in certain conditions :

  • exported getStaticProps : no problem
  • no getStaticProps : same error as OP's
  • when fallback is true and trying to access a non generated at build path : same error again (also tested by cloning the repo)

Code

pages/_middleware.ts

import { NextRequest, NextResponse } from "next/server";

export default function middleware(req: NextRequest) {
  const { pathname } = req.nextUrl;
  // Get hostname (e.g. vercel.com, test.vercel.app, etc.)
  const hostname = req.headers.get("host");


  const currentHost = hostname?.replace(`.${process.env.ROOT_URL}`, "");

  console.log("current host", currentHost);

  if (pathname.startsWith(`/_sites`)) {
    return new Response(null, { status: 404 });
  }

  if (
    !pathname.includes(".") && // exclude all files in the public folder
    !pathname.startsWith("/api") // exclude all API routes
  ) {
    const rewrited_path = `/_sites/${currentHost}${pathname}`;
    console.log(`pushed to ${rewrited_path}`);
   
    return NextResponse.rewrite(rewrited_path);
  }
}

working when visiting /newpage (if the used subdomain path has been generated at build, if not it triggers the error) with getStaticProps :

pages/_sites/[site]/newpage.tsx


export default function NewPage({ domain }) {
  return <div> New Page {domain} </div>;
}


export async function getStaticProps(context) {
  const domain = context.params.site;

  return {
    props: {
      domain,
    },
  };
}

const mockDB = [
  {
    name: "Site 1",
    description: "Subdomain + custom domain",
    subdomain: "domain-1",
  },
  {
    name: "Site 2",
    description: "Subdomain only",
    subdomain: "new-domain",
  },
  {
    name: "Site 3",
    description: "Subdomain only",
    customDomain: "custom-domain.com",
  },
];


export async function getStaticPaths() {
  const site_paths = mockDB.map((elem) => {
    if (elem.customDomain) {
      return { params: { site: elem.customDomain } };
    } else {
      return { params: { site: elem.subdomain } };
    }
  });

  return {
    paths: site_paths,
    fallback: true,
  };
}

Not working when visiting /newpage, get the error

export default function NewPage() {
  return <div>NewPage</div>;
}

from examples.

moinulmoin avatar moinulmoin commented on May 5, 2024

@JohnAllen Could you please help us, man? thank you

from examples.

JohnAllen avatar JohnAllen commented on May 5, 2024

Just change the value of that. What have you tried? Remove it altogether.

from examples.

StitiFatah avatar StitiFatah commented on May 5, 2024

I don't think it has anything to do with the href, I don't have any <Link/> or <a/> in my code as you can see above.

from examples.

moinulmoin avatar moinulmoin commented on May 5, 2024

@JohnAllen ain't you maintaining this example repo?

from examples.

JohnAllen avatar JohnAllen commented on May 5, 2024

Excellent usage of "ain't" as well.

from examples.

moinulmoin avatar moinulmoin commented on May 5, 2024

LOL what makes you think that? Hahahahah @moinulmoin

Haha, don't know. I thought you were maintaining this example repo. My bad! then where are official authors/maintainers? we need help regarding this issue 😣

from examples.

moinulmoin avatar moinulmoin commented on May 5, 2024

@steven-tey help please!

from examples.

StitiFatah avatar StitiFatah commented on May 5, 2024

@steven-tey help please!

I have created a new issue on NextJs' repo since I believe it's related to NextJS in general and not just to the Vercel platform vercel/next.js#32446

from examples.

akinwol avatar akinwol commented on May 5, 2024

@StitiFatah @moinulmoin it's because you don't have corresponding mock data simply adding this to the mock data will solve
{ name: 'Site 4', description: 'Host One', subdomain: 'hostname-1', customDomain: null, },

from examples.

StitiFatah avatar StitiFatah commented on May 5, 2024

@StitiFatah @moinulmoin it's because you don't have corresponding mock data simply adding this to the mock data will solve { name: 'Site 4', description: 'Host One', subdomain: 'hostname-1', customDomain: null, },

@akinwol Hey mate, having it working without adding the corresponding data is the whole the point of the issue, this piece of code

export default function NewPage({ domain }) {
  return <div> New Page {domain} </div>;
}

Should return in the browser NewPage subdomain_used whether or not the subdomain is in the mockDB. If it is already in the mockDB and the path has already been generated generated then it's already fine else fallback:true or fallback:"blocking" should play their roles and re run getStaticProps to the subdomain value.

For proof the whole process is perfectly working when setting fallback to "blocking" but with fallback:true it triggers the error.

Example : I visit domain-1.localhost:3000/newpage/, since the domain-1 subdomain is already in the mockDB it works. But now if I visit domain-25.localhost:3000/newpage/ it works perfectly with fallback:"blocking" but not withfallback:true but it should normally work with both.

from examples.

lfades avatar lfades commented on May 5, 2024

Closing as per the comment above, if the issue still persists please comment again and it'll re-open it.

from examples.

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.