public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        if ($request->attributes->get('_route') !== 'ngbm_ajax_block') {
            return;
        }

        if ($request->attributes->has('ngbmContextUri')) {
            return;
        }

        // This is a naive implementation which removes the need to deconstruct
        // the URI with parse_url/parse_str and then rebuilding it, just to remove
        // a single query parameter with a known name and format.
        $requestUri = preg_replace(
            ['/&page=\d+/', '/\?page=\d+&/', '/\?page=\d+/'],
            ['', '?', ''],
            $request->getRequestUri()
        );

        $request->attributes->set('ngbmContextUri', $requestUri);
    }