Skip to content

Commit 57835cd

Browse files
authored
Merge pull request #330 from kaliber5/fix-fastboot-imgix
Fix broken FastBoot rendering of imgix provider
2 parents 6920c2d + d4bbcd7 commit 57835cd

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

addon/helpers/responsive-image-imgix-provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ export const provider = (
3030
return {
3131
imageTypes: options.formats ?? ['png', 'jpeg', 'webp'],
3232
imageUrlFor(width: number, type: ImageType = 'jpeg'): string {
33-
const url = new URL(`https://${domain}/${normalizeSrc(image)}`);
33+
// In the FastBoot sandbox, the URL global is shadowed by the `url` module. :-(
34+
// See https://github.com/ember-fastboot/ember-cli-fastboot/issues/816
35+
const URLConstructor: typeof URL =
36+
typeof URL === 'function' ? URL : (URL as { URL: typeof URL }).URL;
37+
38+
const url = new URLConstructor(
39+
`https://${domain}/${normalizeSrc(image)}`
40+
);
3441
const params = url.searchParams;
3542

3643
params.set('fm', formatMap[type] ?? type);

tests/dummy/app/router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ export default class Router extends EmberRouter {
88

99
Router.map(function () {
1010
this.route('image');
11+
this.route('cloudinary');
12+
this.route('imgix');
1113
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ResponsiveImage @src={{responsive-image-cloudinary-provider "samples/animals/three-dogs"}} data-test-image/>

tests/dummy/app/templates/imgix.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ResponsiveImage @src={{responsive-image-imgix-provider "pages/approach/agile_2000x1200.jpg"}} data-test-image/>

tests/fastboot/cloudinary-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { module, test } from 'qunit';
2+
import {
3+
setup,
4+
visit /* mockServer */,
5+
} from 'ember-cli-fastboot-testing/test-support';
6+
7+
module('FastBoot | Cloudinary', function (hooks) {
8+
setup(hooks);
9+
10+
test('it renders an image', async function (assert) {
11+
await visit('/cloudinary');
12+
13+
assert.dom('img[data-test-image]').exists();
14+
assert
15+
.dom('img[data-test-image]')
16+
.hasAttribute('src', new RegExp('https://res.cloudinary.com/kaliber5/'));
17+
});
18+
});

tests/fastboot/imgix-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { module, test } from 'qunit';
2+
import {
3+
setup,
4+
visit /* mockServer */,
5+
} from 'ember-cli-fastboot-testing/test-support';
6+
7+
module('FastBoot | Imgix', function (hooks) {
8+
setup(hooks);
9+
10+
test('it renders an image', async function (assert) {
11+
await visit('/imgix');
12+
13+
assert.dom('img[data-test-image]').exists();
14+
assert
15+
.dom('img[data-test-image]')
16+
.hasAttribute('src', new RegExp('https://kaliber5.imgix.net/'));
17+
});
18+
});

0 commit comments

Comments
 (0)