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

fix(prerender): decode urls to allow comma in the x-nitro-prerender header #799

Merged
merged 1 commit into from
Jan 3, 2023

Conversation

posixpascal
Copy link
Contributor

Hey, first timer here πŸŽ‰.

πŸ”— Linked issue

nuxt/image#701

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When using @nuxt/image-edge with Nuxt 3 the default image provider is IPX which allows arbitrary image manipulation through URLs.

When using multiple transformations on an image the different transformations are seperated by a comma like this in the final image URL:

/_ipx/q_50,s_10x10/images/nitropack.png

@nuxt/image-edge appends these URLs to the X-Nitro-Prerender header without encoding the URL.
The header will then be split by "," when prerendering the site which leads to the following URLs being prerendered:

  • _ipx/q_50
  • s_10x10/images/nitropack.png

This results in some images not being properly prerendered and/or missing in the final output build when running yarn run generate

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 changed the title fix(prerender): Decode URL to allow comma in the x-nitro-prerender header fix(prerender): decode urls to allow comma in the x-nitro-prerender header Jan 3, 2023
src/prerender.ts Outdated
_links.push(...header.split(",").map((i) => i.trim()));
_links.push(...header.split(",")
.map((i) => decodeURIComponent(i))
.map((i) => i.trim()));
Copy link
Member

Choose a reason for hiding this comment

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

I think we should move trim before decode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch. I've updated the PR.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

THanks!

@pi0 pi0 merged commit f642abc into unjs:main Jan 3, 2023
_links.push(...header.split(",").map((i) => i.trim()));
_links.push(...header.split(",")
.map((i) => i.trim())
.map((i) => decodeURIComponent(i));
Copy link
Contributor

Choose a reason for hiding this comment

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

you are missing a ) here:

Suggested change
.map((i) => decodeURIComponent(i));
.map((i) => decodeURIComponent(i)));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh my bad. Fixed it in #801. πŸ˜”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants