-
Notifications
You must be signed in to change notification settings - Fork 17
feat(image): support referrerpolicy on rendered images #4056
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
base: main
Are you sure you want to change the base?
Changes from all commits
4679e71
974c671
c7af85b
13f5f7f
807914c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. limel-file-viewer can also display images. perhaps it could use this feature too
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,5 +108,25 @@ describe('limel-list-item', () => { | |
|
|
||
| const imgEl = root.querySelector('img'); | ||
| expect(imgEl).not.toBeNull(); | ||
| expect(imgEl?.hasAttribute('referrerpolicy')).toBe(false); | ||
| }); | ||
|
|
||
| it('forwards referrerpolicy to the rendered image when set', async () => { | ||
| const imgSrc = | ||
| 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='; | ||
| const { root, waitForChanges } = await render( | ||
| <limel-list-item | ||
| text="Pic" | ||
| image={{ | ||
| src: imgSrc, | ||
| alt: 'a', | ||
| referrerpolicy: 'no-referrer', | ||
| }} | ||
| ></limel-list-item> | ||
| ); | ||
| await waitForChanges(); | ||
|
|
||
| const imgEl = root.querySelector('img'); | ||
| expect(imgEl?.getAttribute('referrerpolicy')).toEqual('no-referrer'); | ||
| }); | ||
|
Comment on lines
+114
to
131
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win Consider adding similar e2e coverage for chip and card components. List-item now has tests for both 🤖 Prompt for AI Agents |
||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,13 @@ export interface Image { | |
| * - `eager` means that the image will be loaded as soon as possible. | ||
| */ | ||
| loading?: 'lazy' | 'eager'; | ||
|
|
||
| /** | ||
| * The `referrerpolicy` attribute of the image. Set to `'no-referrer'` | ||
| * when `src` points to a third-party service that should not receive | ||
| * the originating page URL in the `Referer` header (e.g. external | ||
| * favicon or avatar services). When omitted, the attribute is not | ||
| * emitted and the browser's default referrer policy applies. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we always default to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be the natural privacy-positive default, but it'd be observable across every Leaning toward keeping it opt-in here and letting consumers like lime-crm-components set |
||
| */ | ||
| referrerpolicy?: ReferrerPolicy; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { FunctionalComponent, h } from '@stencil/core'; | ||
| import { Image } from '../global/shared-types/image.types'; | ||
|
|
||
| interface ImageTemplateProps { | ||
| image: Image; | ||
| } | ||
|
|
||
| /** | ||
| * Renders an `Image` as a plain `<img>` element. Centralises the | ||
| * attribute forwarding (including the spread-cast workaround for | ||
| * `referrerpolicy`) so consumer components do not have to reimplement | ||
| * it. Intended for internal use by lime-elements components that | ||
| * accept an `Image`-shaped prop. | ||
| * | ||
| * @param props | ||
| * @param props.image - the image to render | ||
| * @internal | ||
| */ | ||
| export const ImageTemplate: FunctionalComponent<ImageTemplateProps> = ({ | ||
| image, | ||
| }) => { | ||
| // Spread-cast: Stencil's `ImgHTMLAttributes` typing omits | ||
| // `referrerpolicy`, so the attribute can't be passed directly. | ||
| // Tracked upstream at https://github.com/stenciljs/core/issues/6692 | ||
| // — once that lands, this cast can be removed. | ||
| const referrerPolicyAttr: { referrerpolicy?: Image['referrerpolicy'] } = | ||
| image.referrerpolicy ? { referrerpolicy: image.referrerpolicy } : {}; | ||
|
|
||
| return ( | ||
| <img | ||
| src={image.src} | ||
| alt={image.alt} | ||
| loading={image.loading ?? 'lazy'} | ||
| {...(referrerPolicyAttr as Record<string, string>)} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| /> | ||
| ); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.