Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 0129467

Browse files
committed
fix: add fix for src attribute
1 parent 8a1569d commit 0129467

File tree

8 files changed

+92
-6
lines changed

8 files changed

+92
-6
lines changed

.storybook/assets/chakra.png

96.9 KB
Loading

.storybook/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ module.exports = async ({ config, mode }) => {
1515
'sass-loader'
1616
],
1717
});
18+
config.resolve.alias = {
19+
...config.resolve.alias,
20+
"@/": path.resolve(__dirname, "./"),
21+
};
1822

1923
// Return the altered config
2024
return config;

packages/chakra-ui-core/src/CImage/CImage.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ const CImage = {
5555
methods: {
5656
loadImage (src, srcset) {
5757
const image = new window.Image()
58-
image.srcset = srcset
59-
image.src = src
58+
if (srcset) {
59+
image.srcset = srcset
60+
}
61+
if (src) {
62+
image.src = src
63+
}
6064

6165
image.onload = (event) => {
6266
this.hasLoaded = true
@@ -76,6 +80,7 @@ const CImage = {
7680
} else {
7781
imageProps = { src: this.hasLoaded ? this.src : this.fallbackSrc, srcset: this.srcset }
7882
}
83+
debugger
7984
return h(CNoSsr, [
8085
h('img', {
8186
class: this.className,

packages/chakra-ui-core/src/CImage/CImage.stories.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ storiesOf('UI | Image', module)
88
<CImage
99
shadow="sm"
1010
htmlWidth="100px"
11-
src="https://bit.ly/chakra-jonathan-bakebwa"
11+
src="https://bit.ly/chakra-jonathan-bakebw3a"
12+
srcset="https://bit.ly/chakra-jonathan-bakebwa"
13+
/>
14+
`
15+
}))
16+
.add('Webpack required image', () => ({
17+
components: { CImage },
18+
template: `
19+
<CImage
20+
shadow="sm"
21+
htmlWidth="100px"
22+
:src="require('@/assets/chakra.png')"
1223
/>
1324
`
1425
}))

packages/chakra-ui-core/src/CImage/tests/CImage.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@ it('fallback src works', async () => {
4646
})
4747
})
4848

49-
it('srcset works', async () => {
50-
renderComponent({ template: '<CImage alt="My Image Description" src="LOAD_SUCCESS_SRC" srcset="LOAD_SUCCESS_SRC 400w" />' })
49+
it('"srcset" should work and be prioritized over "src" if provided to CImage', async () => {
50+
const { asFragment } = renderComponent({ template: '<CImage alt="My Image Description" src="LOAD_SUCCESS_SRC" srcset="LOAD_SUCCESS_SRC 400w" />' })
5151
await wait(() => {
5252
expect(screen.getByAltText(/My Image Description/i)).toHaveAttribute('srcset', 'LOAD_SUCCESS_SRC 400w')
53+
expect(asFragment()).toMatchSnapshot()
54+
})
55+
})
56+
57+
it('should use src if srcset provided is undefined', async () => {
58+
const { asFragment } = renderComponent({ template: '<CImage alt="My Image Description" src="LOAD_SUCCESS_SRC" srcset="LOAD_FAILURE_SRC" />' })
59+
await wait(() => {
60+
expect(screen.getByAltText(/My Image Description/i)).toHaveAttribute('src', 'LOAD_SUCCESS_SRC')
61+
expect(asFragment()).toMatchSnapshot()
5362
})
5463
})

packages/chakra-ui-core/src/CImage/tests/__snapshots__/CImage.test.js.snap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`"srcset" should work and be prioritized over "src" if provided to CImage 1`] = `
4+
<DocumentFragment>
5+
<img
6+
alt="My Image Description"
7+
class="css-0"
8+
data-chakra-component="CImage"
9+
src="LOAD_SUCCESS_SRC"
10+
srcset="LOAD_SUCCESS_SRC 400w"
11+
/>
12+
</DocumentFragment>
13+
`;
14+
315
exports[`should render correctly 1`] = `
416
<DocumentFragment>
517
<img
@@ -11,3 +23,15 @@ exports[`should render correctly 1`] = `
1123
/>
1224
</DocumentFragment>
1325
`;
26+
27+
exports[`should use src if srcset provided is undefined 1`] = `
28+
<DocumentFragment>
29+
<img
30+
alt="My Image Description"
31+
class="css-0"
32+
data-chakra-component="CImage"
33+
src="LOAD_SUCCESS_SRC"
34+
srcset="LOAD_FAILURE_SRC"
35+
/>
36+
</DocumentFragment>
37+
`;

website/pages/contributors.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
<carbon-ad />
1212

13+
<c-image :src="require('@/assets/logo/[email protected]')" />
14+
1315
<c-box>
1416
<c-box v-for="(person, _i) in contributors" :key="_i" bb="1px solid" border-color="gray.200" p="3">
1517
<c-text font-weight="bold" mt="3" font-size="1.3rem">

website/static/sw.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,32 @@
1-
// THIS FILE SHOULD NOT BE VERSION CONTROLLED
1+
importScripts('https://cdn.jsdelivr.net/npm/[email protected]/workbox/workbox-sw.js')
2+
3+
// --------------------------------------------------
4+
// Configure
5+
// --------------------------------------------------
6+
7+
// Set workbox config
8+
workbox.setConfig({
9+
"debug": false
10+
})
11+
12+
// Start controlling any existing clients as soon as it activates
13+
workbox.core.clientsClaim()
14+
15+
// Skip over the SW waiting lifecycle stage
16+
workbox.core.skipWaiting()
17+
18+
workbox.precaching.cleanupOutdatedCaches()
19+
20+
// --------------------------------------------------
21+
// Precaches
22+
// --------------------------------------------------
23+
24+
// Precache assets
25+
26+
// --------------------------------------------------
27+
// Runtime Caching
28+
// --------------------------------------------------
29+
30+
// Register route handlers for runtimeCaching
31+
workbox.routing.registerRoute(new RegExp('/_nuxt/'), new workbox.strategies.CacheFirst ({}), 'GET')
32+
workbox.routing.registerRoute(new RegExp('/'), new workbox.strategies.NetworkFirst ({}), 'GET')

0 commit comments

Comments
 (0)