Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use http-client-hints #10

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

userquin
Copy link
Owner

@userquin userquin commented Oct 13, 2024

Description

This PR also includes:

  • add example using Nitro Event Handler in dev and production
  • move the playground to compat. v4 format

/cc @danielroe @pi0 no idea why it is not working (dev or build): I'll try tmr to move the repo to monorepo adding the playground to the workspaces.

imagen

imagen

Linked Issues

Additional Context


Tip

The author of this PR can publish a preview release by commenting /publish below.

@userquin userquin requested a review from danielroe October 13, 2024 19:29
useRequestHeaders,
} from '#imports'
import { writeHeaders } from './headers'
import { defineNuxtPlugin, useCookie, useRequestHeaders, useRuntimeConfig } from '#imports'
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace useRuntimeConfig with useAppConfig in all plugins and remove the registration from the configuration

@userquin
Copy link
Owner Author

userquin commented Oct 18, 2024

So, the problem here is about adding an event handler to handle image requests.

Dev server (playground):

  • the nuxt http client hints plugin not being registered or invoked (src/runtime/server/plugin.ts, the index.ts not being used, it is an event handler)
  • there is no way to declare an event handler to intercept image requests other than including it in the nitro.devHandlers array (playground nuxt config file)

Build + start SSR app via node (playground):

  • the nuxt http client hints being registered and invoked on image requests (rn added afterResponse nitro hook to log the http client hints for image requests)
  • there is no way to declare an event handler to intercept image request in the playgrounds: the current server/image.ts not being invoked, only with some assets like / and favicon.ico (playground); tested with router: '' and middleware: true'

@userquin
Copy link
Owner Author

userquin commented Oct 18, 2024

There is also a weird behavior in the client plugins, the client runtime module hook (http-client-hints:client-hints) not being called in the plugins/hints.client.ts in the playground, the client plugin registred in src/utils/configuration.ts module with enforce: 'post' and without dependsOn (addClientHintsPlugin) being called after the plugins/hints.client.ts and so will not be called.

You can check it adding a breakpoint in both plugins.

It is enforce: 'post' not order: 'post' 🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️🤦‍♂️

@userquin
Copy link
Owner Author

We can expose the utilities instead exposing a plugin, but then we're moving the problem to the consumer, I want to check it here with some minimal working example.

@userquin
Copy link
Owner Author

/publish

@userquin userquin marked this pull request as ready for review October 18, 2024 22:25
Copy link

pkg-pr-new bot commented Oct 18, 2024

pnpm add https://pkg.pr.new/nuxt-http-client-hints@10

commit: 7f9fffb

@userquin
Copy link
Owner Author

Looks like we have problems with nitro cache headers event handler. I guess when vary header added the browser should change some http request headers.

chore: cleanup playground
chore: export server utils subpackage instead using nitro imports
@userquin
Copy link
Owner Author

@userquin userquin changed the title feat: add Nitro event handler feat: use http-client-hints Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant