|
6 | 6 | import Tooltip from '$lib/components/common/Tooltip.svelte'; |
7 | 7 | import { packageVersionsStore } from '$lib/stores/packageVersionsStore'; |
8 | 8 | import { exampleGroupsStore } from '$lib/stores/examplesContext'; |
| 9 | + import { notebookStore } from '$lib/stores/notebookStore'; |
9 | 10 | import { groupByCategory } from '$lib/notebook/manifest'; |
10 | 11 | import { packages } from '$lib/config/packages'; |
11 | 12 | import type { PageData } from './$types'; |
|
38 | 39 | }; |
39 | 40 | }); |
40 | 41 |
|
41 | | - // Reset Pyodide namespace when example changes (but don't terminate) |
42 | | - // {#key} on Notebook handles component destruction and store cleanup via onDestroy |
| 42 | + // Reset Pyodide namespace and notebook store when example changes |
43 | 43 | $effect(() => { |
44 | 44 | const slug = data.meta.slug; |
45 | 45 |
|
46 | 46 | return async () => { |
| 47 | + // Cell IDs are prefixed with the slug, so old cells won't collide |
| 48 | + // with new ones. But we still need to clean up stale store entries |
| 49 | + // and reset the Python namespace. |
| 50 | + notebookStore.reset(); |
47 | 51 | try { |
48 | 52 | const { reset } = await import('$lib/pyodide'); |
49 | 53 | await reset(); |
|
86 | 90 | downloadUrl={`${versionBasePath}/notebooks/${data.meta.file}`} |
87 | 91 | /> |
88 | 92 |
|
89 | | - {#key data.meta.slug} |
90 | | - <Notebook |
91 | | - notebook={data.notebook} |
92 | | - basePath={versionBasePath} |
93 | | - precomputedOutputs={data.outputs} |
94 | | - {figuresBasePath} |
95 | | - showStaticOutputs={true} |
96 | | - executable={data.meta.executable} |
97 | | - /> |
98 | | - {/key} |
| 93 | + <Notebook |
| 94 | + notebook={data.notebook} |
| 95 | + basePath={versionBasePath} |
| 96 | + precomputedOutputs={data.outputs} |
| 97 | + {figuresBasePath} |
| 98 | + showStaticOutputs={true} |
| 99 | + executable={data.meta.executable} |
| 100 | + /> |
99 | 101 | </div> |
100 | 102 |
|
101 | 103 | <style> |
|
0 commit comments