Skip to content

Commit a6cc764

Browse files
jgbowseryanick
authored andcommittedApr 7, 2022
fix: always destroy most recent component on rerender
1 parent de7ec33 commit a6cc764

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed
 

‎.all-contributorsrc

+10
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@
121121
"contributions": [
122122
"test"
123123
]
124+
},
125+
{
126+
"login": "jgbowser",
127+
"name": "John Bowser",
128+
"avatar_url": "https://avatars.githubusercontent.com/u/66637570?v=4",
129+
"profile": "https://johnbowser.dev/",
130+
"contributions": [
131+
"code",
132+
"test"
133+
]
124134
}
125135
],
126136
"contributorsPerLine": 7,

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Thanks goes to these people ([emoji key][emojis]):
134134
<td align="center"><a href="https://github.com/MirrorBytes"><img src="https://avatars3.githubusercontent.com/u/22119469?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bob</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/issues?q=author%3AMirrorBytes" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=MirrorBytes" title="Code">💻</a></td>
135135
<td align="center"><a href="https://github.com/ronmerkin"><img src="https://avatars.githubusercontent.com/u/17492527?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ron Merkin</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=ronmerkin" title="Code">💻</a></td>
136136
<td align="center"><a href="http://www.benmccann.com"><img src="https://avatars.githubusercontent.com/u/322311?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ben McCann</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=benmccann" title="Tests">⚠️</a></td>
137+
<td align="center"><a href="https://johnbowser.dev/"><img src="https://avatars.githubusercontent.com/u/66637570?v=4?s=100" width="100px;" alt=""/><br /><sub><b>John Bowser</b></sub></a><br /><a href="https://github.com/testing-library/svelte-testing-library/commits?author=jgbowser" title="Code">💻</a> <a href="https://github.com/testing-library/svelte-testing-library/commits?author=jgbowser" title="Tests">⚠️</a></td>
137138
</tr>
138139
</table>
139140

‎src/pure.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const render = (
4949
return { props: options }
5050
}
5151

52-
const component = new ComponentConstructor({
52+
let component = new ComponentConstructor({
5353
target,
5454
...checkProps(options)
5555
})
@@ -67,15 +67,15 @@ const render = (
6767
if (componentCache.has(component)) component.$destroy()
6868

6969
// eslint-disable-next-line no-new
70-
const newComponent = new ComponentConstructor({
70+
component = new ComponentConstructor({
7171
target,
7272
...checkProps(options)
7373
})
7474

75-
containerCache.set(container, { target, newComponent })
76-
componentCache.add(newComponent)
75+
containerCache.set(container, { target, component })
76+
componentCache.add(component)
7777

78-
newComponent.$$.on_destroy.push(() => { componentCache.delete(newComponent) })
78+
component.$$.on_destroy.push(() => { componentCache.delete(component) })
7979
},
8080
unmount: () => {
8181
if (componentCache.has(component)) component.$destroy()

0 commit comments

Comments
 (0)
Please sign in to comment.