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: stable release #748

Merged
merged 55 commits into from
Jan 19, 2025
Merged

feat: stable release #748

merged 55 commits into from
Jan 19, 2025

Conversation

ascorbic
Copy link
Owner

@ascorbic ascorbic commented Dec 15, 2024

This is a major update, with changes to the API of all frameworks. This will not affect you if you are just using the components with default options, but if you are passing custom transformers or specifying the CDN then you will need to update your code.

To try it, install the preview build from pkg.pr.new

The new provider transformers and types are implemented in ascorbic/unpic#133

Breaking changes

  • The cdnOptions property has been removed. Use the new options property instead.
  • The transformer property has been removed from the default Image component. Import the base component and specify the transformer there instead. The type signature for the transformer has also changed. See the unpic library documentation for more information.
  • The cdn property has been removed. Either use the new fallback property or import the base component and pass a single provider to it.

Changes

Most of the changes are because of a new approach to handling individual image CDNs and providers in the base Unpic library. This is designed to make Unpic more flexible, efficient and modular. It also introduces support for type-safe custom operations and options for each provider.

Provider operations

Supported frameworks: All except webc and lit.

The new operations property allows you to specify custom operations for each provider. Many image CDNs support dozens of custom operations. Previously these were hard to use with Unpic. The new operations property gives type-safe support for all supported features of each provider. This works even if you have images from multiple providers in the same component, as you can specify options for each provider separately.

image
<Image
  src="https://example.com/image.jpg"
  operations={{ imgix: { flip: "h" }, bunny: { flop: true } }}
/>

The operations are all type-safe, with JSDoc comments and TypeScript definitions for all supported operations. This means you can get autocompletion and type checking for all operations.

Provider options

Supported frameworks: All except webc and lit.

The new options property allows you to specify custom options for each provider. This is similar to the current cdnOptions property, but with type-safe support for all options of each provider. This allows you to specify options such as account IDs and domains for each provider.

image

Fallback providers

Supported frameworks: All. The astro and nextjs frameworks default to the framework's image provider as fallback.

The new fallback property allows you to specify a fallback provider for each image. This allows you to use auto-detection for image CDNs as now, but also specify a fallback provider for local images and images from unknown providers. This is useful if you have a mix of images from different sources, and want to ensure that all images are handled correctly. For example, you may have a Contentful blog hosted on Netlify, with images that are mostly hosted on Contentful (a supported CDN), but also some images from third-parties or your own server. You can specify Netlify as the fallback provider so that it uses the Netlify Image CDN for all images that are not from Contentful or another supported provider. This will be all handled automatically.

image

Base component

Supported frameworks: All except webc, lit and angular.

Previously, the Image and Source components always loaded support for every provider, even if you specified a single provider or custom transformer. This is fine if you are using auto-detection, but many people wanted to use the components in a more custom or modular way. The new base components allow you to use the Unpic component without any of the automatic detection and transform logic. You can provide your own transformer, or use a single, tree-shakable provider import. This is useful if you are using a single provider, or if you are building a custom component based on Unpic.

// Import from the `/base` subpath
import { Image } from "@unpic/react/base";
// Import the transformer for the provider you are using
import { transform } from "unpic/providers/imgix";

export const Hero = () => (
  <Image
    src="https://images.unsplash.com/photo-1734108039189-f6c123288381"
    transformer={transform}
    operations={{ sepia: 50 }}
  />
);

The operations and options properties are still type-safe and inferred from the transformer, and you don't need to specify the provider name in the operations object.

Copy link

changeset-bot bot commented Dec 15, 2024

🦋 Changeset detected

Latest commit: 13b27cd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@unpic/svelte Major
@unpic/react Major
@unpic/core Major
@unpic/angular Major
@unpic/astro Major
@unpic/lit Major
@unpic/preact Major
@unpic/qwik Major
@unpic/solid Major
@unpic/vue Major
@unpic/webc Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

netlify bot commented Dec 15, 2024

Deploy Preview for unpic-docs ready!

Name Link
🔨 Latest commit 13b27cd
🔍 Latest deploy log https://app.netlify.com/sites/unpic-docs/deploys/678d19a9ef6689000818835a
😎 Deploy Preview https://deploy-preview-748.preview.unpic.pics
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 15, 2024

Deploy Preview for unpic-angular ready!

Name Link
🔨 Latest commit 13b27cd
🔍 Latest deploy log https://app.netlify.com/sites/unpic-angular/deploys/678d19a9ce7afb0008ca2287
😎 Deploy Preview https://deploy-preview-748--unpic-angular.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Dec 15, 2024

Deploy Preview for unpic-next ready!

Name Link
🔨 Latest commit 13b27cd
🔍 Latest deploy log https://app.netlify.com/sites/unpic-next/deploys/678d19a9f9e6a0000855951b
😎 Deploy Preview https://deploy-preview-748--unpic-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ascorbic ascorbic changed the title feat: V1 feat: stable release Dec 28, 2024
@ascorbic ascorbic marked this pull request as ready for review December 28, 2024 10:41
@benmccann
Copy link
Contributor

I think it'd probably be nice to have a way to be able to set a default transformer. I haven't used CDNs much, so don't know how much of an issue it is to have to set the transformer each time you have an image, but it feels like it'd be easier to do it just once for the whole app.

@ascorbic
Copy link
Owner Author

ascorbic commented Jan 9, 2025

@benmccann it's hard to set defaults outside of a metaframework. Even using env vars has caused issues in the places I tried it, because of platform-specific differences. In most cases the best approach is to create your own wrapper component, though obviously the syntax for that varies by framework too. That lets you import just the transformer you need.

@benmccann
Copy link
Contributor

Yeah, wrapper component seems like a good solution. Might be worth explicitly suggesting that in the docs if it's not already

@ascorbic
Copy link
Owner Author

@benmccann I added exactly that this morning! https://deploy-preview-748.preview.unpic.pics/custom/

@ascorbic ascorbic enabled auto-merge (squash) January 19, 2025 15:28
@ascorbic ascorbic merged commit cd0fe95 into main Jan 19, 2025
22 of 25 checks passed
@ascorbic ascorbic deleted the v1 branch January 19, 2025 15:28
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.

3 participants