Skip to content

Navigate function does not work on integrations that do not need a hydration entrypoint #12855

@thejackshelton

Description

@thejackshelton

Astro Info

Astro                    v5.1.1
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @qwikdev/astro

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

TLDR:

As an environment agnostic first ui-framework (e.g server, client), Qwik fully supports Astro's client router.

However, the navigate function for the client router does not work when building in the Qwik integration (it does in dev mode). Likely due to pre-existing expectations of hydration.

We have gotten feedback that this is something that should be supported given how it's explained and consumed in a React component in the Astro docs. We can see that it already works in dev mode. QwikDev/astro#40

image

The error we get when building:

vite]: Rollup failed to resolve import "astro:transitions/client" from "/Users/jackshelton/dev/open-source/qwikdev-astro/apps/demo/src/components/qwik/counter.tsx_Counter_component_Fragment_button_onClick_1_KfE1Zu3VTRY.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rollupOptions.external`
  Stack trace:
    at viteWarn (file:///Users/jackshelton/dev/open-source/qwikdev-astro/node_modules/.pnpm/vite@5.4.11_@types+node@22.10.2/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:65589:17)
    at onRollupWarning (file:///Users/jackshelton/dev/open-source/qwikdev-astro/node_modules/.pnpm/vite@5.4.11_@types+node@22.10.2/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:65619:5)
    at file:///Users/jackshelton/dev/open-source/qwikdev-astro/node_modules/.pnpm/rollup@4.29.1/node_modules/rollup/dist/es/shared/node-entry.js:19537:13
    at ModuleLoader.handleInvalidResolvedId (file:///Users/jackshelton/dev/open-source/qwikdev-astro/node_modules/.pnpm/rollup@4.29.1/node_modules/rollup/dist/es/shared/node-entry.js:20152:26)
 ELIFECYCLE  Command failed with exit code 1.
 ELIFECYCLE  Command failed with exit code 1.

Longer explanation:

Astro integrations that are renderers / frameworks require the addRenderer function.

This function provides a:

  • serverEntrypoint
  • clientEntrypoint

The client entrypoint is mainly needed for hydration based frameworks. This is also how Astro uses partial hydration to create Astro islands.

In the Qwik integration, we do not need a client entrypoint at all, because there is nothing to hydrate, the server is able to communicate with the client without needing to sync up missing information.

This also means that Qwik components do not need the client directives (e.g client:load, client:visible) etc. to be interactive.

It would appear that somewhere in Astro core, there is a pre-existing expectation that the navigate function is needed with a client hydration entrypoint when building the application.

It may be possible to create a workaround like a virtual module in the Qwik Astro integration, however, I would prefer not to patch core functionality of Astro, and would be happy to help with making sure that people using Astro with Qwik continue to have the same developer experience they know and enjoy.

Happy to pair with someone on this in core.

What's the expected result?

We would expect the functionality to work similar to how it does with the React integration in the docs:

import { component$ } from '@builder.io/qwik';
import { navigate } from 'astro:transitions/client';

export const Navigation = component$(() => {
  return <button onClick$={() => navigate('/test')}>Navigate to test</button>;
});

When building, rollup correctly resolves the Astro client transitions import, and does the same programmatic client rotuer functionality as dev mode in production.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-n2jvyyx5?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions