Chris-Adiante
Chris-Adiante
DDeno
Created by Chris-Adiante on 10/19/2023 in #help
[RESOLVED] Async Route vs Sync Route: Signatures are error-prone
I am new to Deno Fresh and I ran into a strange bug (on my side), when changing a sync route to an async route, because I was getting the Request instead of the RouteContext/PageProps. As in the docs, I was using exported default functions (instead of typed Fat-Arrow-Functions) to define my routes. When changing a route to async, the compiler would not (and could not) warn me, that I am now accessing the wrong property, because at runtime the AsyncRoute will get an extra parameter "Request" as the first (!!!) parameter. A few questions pop up there for me: - Why don't we pass in the request in sync routes? I think it could be helpful in a sync route, too. - Why do we have such an incompatible signature for two very similar things (sync vs. async route)? I would add it as second parameter, as most routes do not need it (even the example in the docs happily ignores it) or even better, just add it to the route context. - Why don't we at least explicitly hint users in the docs in a very obvious way, that async routes and sync routes have an incompatible signature? I know the first two would be a really nasty breaking change, because the compiler/IDE would not be of much help, but updating the docs could be helpful.
7 replies