next-drupal
next-drupal copied to clipboard
404 drupal.translatePathFromContext(context) on any path.
Hi,
I'm trying to start using next-drupal, i follow the tutorial, i'm using a working drupal to test and next-drupal-basic-starter to test it.
Homepage with article from the drupal work fine, but a soon as i click on a link, error 404.
in [...slug].tsx
let path = await drupal.translatePathFromContext(context)
return only null, so i can't go further, and i have no idea where to start searching ^^
context variable
context: { params: { slug: [ 'blog/my-article-title' ] }, locales: undefined, locale: undefined, defaultLocale: undefined }
Thx for the help :)
@spiderneo Can you check if you have the required patches applied? See https://next-drupal.org/learn/quick-start/apply-patches
Hi @shadcn, yes both patches (decoupled_router and subrequests) are applied to the Drupal. Despite the fact that i regenerated all link Alais in Drupal (there where OK on the json), they were not served to the nextjs app (router/translate-path), after a good clear cache, it seems to work !
i can go futher now :D Thank you for your response ! 👍 and great module !
Just a noob question if i want to mess with the src folder of next-drupal, how can i rebuild it too the dist folder ? Sorry i'm not very comfortable with nodejs for now.
We use a monorepo for developing the packages. The contributing guide might be helpful: https://github.com/chapter-three/next-drupal/blob/main/CONTRIBUTING.md
You could also use something like https://github.com/ds300/patch-package to make changes.
If you see anything that could be improved, feel free to open a PR :)
Thank you ;) i'm only at the beginning, but i'll try :D
So, after setting another source of drupal, i got the issue again (i know :) ) I'm having the issue on the drupal on path: https://sneo.fr/fr/router/translate-path?path=blog/my-article is not returning proper json but drupal Error.
Drupal\Core\Entity\Query\QueryException: Invalid specifier 'redirect_source__path' in Drupal\Core\Entity\Query\Sql\Tables->addField() (line 314 of core/lib/Drupal/Core/Entity/Query/Sql/Tables.php).
Drupal\Core\Entity\Query\Sql\Condition->compile(Object) (Line: 176) Drupal\Core\Entity\Query\Sql\Query->compile() (Line: 80) Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 74) Drupal\decoupled_router\EventSubscriber\RedirectPathTranslatorSubscriber->onPathTranslation(Object, 'decoupled_router.translate_path', Object) call_user_func(Array, Object, 'decoupled_router.translate_path', Object) (Line: 142) Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, Object) (Line: 76) Drupal\decoupled_router\Controller\PathTranslator->translate(Object) call_user_func_array(Array, Array) (Line: 123) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 564) Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97) Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 159) Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81) Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67) Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58) Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106) Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85) Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49) Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 50) Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48) Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51) Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23) Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709) Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
So the issue is on Drupal side, the patch for decoupled_router is changing redirect_source.path to redirect_source__path which on my instance is not good and generate the error, this lead to the 404.
so just changing redirect_source__path to redirect_source.path on line 70 on /web/modules/contrib/decoupled_router/src/EventSubscriber/RedirectPathTranslatorSubscriber.php eliminate the error.
I have the same problem here. TranslatePathFromContext returns me a 404, for all paths. If I go to the "content" part of Drupal, on a node with "preview mode", I get the preview with my data, and the 404 disappears on the Next.js side, but when I restart the Next.js process, I got a 404 again.
To achieve my goals and for the 404s to disappear, I have to add the param "{ withAuth: true }" to my Drupal requests (like the TranslatePathFromContext
method). Without this, requests seem to be sent as "anonymously", despite using the "DrupalClient" client with the auth (bear) property. I also noticed that for the anonymous user the "View contents" option is unchecked on Drupal. When I try to check it with an administrator account, I get a success message but finally it's not checked...
hello no news here, but the problem is because /router/translate-path has format=json on routing.yml, so it is forcing Accept:"application/json" header, this project by default applies Accept:"application/vnd.api+json". My temporary solution was to create another drupal client on lib/drupal.ts with Accept:"application/vnd.api+json" and use this one on calls to translatePathFromContext.