Giter Site home page Giter Site logo

Comments (9)

y-nk avatar y-nk commented on September 13, 2024 1

yes it is. but i doubt fixing the dev server will be easier. this is a 3 lines patch which can be applied with patch-package and gives the hand to userland through the middleware. so i think it's pretty ok until the maintainers finally decide to have a look at this. (cc @leerob i had mentioned this to you on X)

from next.js.

abhi12299 avatar abhi12299 commented on September 13, 2024 1

yeah - its' not a trivial fix. let's see what happens with this

from next.js.

y-nk avatar y-nk commented on September 13, 2024

somehow related: #53887

from next.js.

y-nk avatar y-nk commented on September 13, 2024

looking further, the regexes generated for the routes seem to ignore totally the generateStaticParams

image

from next.js.

y-nk avatar y-nk commented on September 13, 2024

after a good round of console.log (and from my candid PoV of next), it seems like the AppPageRouteMatcher does not contain data from getStaticParams, therefore it's impossible to get an accurate route matching.

Route definition is passed here, but lacks of any kind of ref to getStaticParams :/

const filename = this.normalizers.filename.normalize(manifest[page])
const bundlePath = this.normalizers.bundlePath.normalize(page)

from next.js.

y-nk avatar y-nk commented on September 13, 2024

of course i want to state clear that i know this:

image

but still routes imho should abide to the result of this function and pass to other matchers before making a decision. here is seems the logic is → match the path blindly regardless of the values in params, then render the route no matter what.

it's utterly deceptive because it's like not using a data validation library (the valid values returned from generateStaticParams) and then pass unvalidated/wrong values to a component.

from next.js.

abhi12299 avatar abhi12299 commented on September 13, 2024

good find, @y-nk.. I'm looking into this and found out that this only happens in dev mode. Production build works as expected. The issue you linked has a PR by one of the maintainers: #54364 - I this issue is stemming from the code changes here. Will investigate further.

Update: this has nothing to do with this PR. The behaviour of the generateStaticParams function in dev mode as you highlighted above is the reason for this issue. The route regex being made does not take into consideration the static params for a given page. It just creates those regexes based on the folder structure. I'm not sure if the maintainers would want to change this behaviour :/

from next.js.

y-nk avatar y-nk commented on September 13, 2024

@abhi12299 i have found an (slightly ugly) way to make it work, which i think could be used as a "ultimate manual mode" feature.

currently my idea is to add some code for manual/force route matching based on headers here:

for (const route of dynamicRoutes) {
// when resolving fallback: false the
// render worker may return a no-fallback response
// which signals we need to continue resolving.
// TODO: optimize this to collect static paths
// to use at the routing layer
if (invokedOutputs?.has(route.page)) {
continue
}

such as:

            for (const route of dynamicRoutes) {
              if (req.headers['x-resolved-route']) {
                // skip the desired route was provided in headers
                if (route.page !== req.headers['x-resolved-route']) {
                  continue;
                }
              }

then we can add this internal header in the middleware like this:

image

from next.js.

abhi12299 avatar abhi12299 commented on September 13, 2024

This is equivalent to hard coding the route match rules in the codebase.

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.