Skip to content

Commit

Permalink
Allow components to import svelte lifecycle bits (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrs authored Apr 22, 2023
2 parents 5c2fe05 + a84f2f4 commit 6bcc110
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/_site/components/Counter.island.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<script>
import Nested from "./Nested.svelte";
import Nested from './Nested.svelte'
import { onMount } from 'svelte'
export let count = 3;
const SSR = typeof document === "undefined";
export let count = 3
let mounted = false
onMount(async () => {
mounted = true
})
</script>

<button disabled={SSR} on:click={() => count--}> -1 </button>
<button disabled={!mounted} on:click={() => count--}> -1 </button>
{count}
<button disabled={SSR} on:click={() => count++}> +1 </button>
<button disabled={!mounted} on:click={() => count++}> +1 </button>

<Nested {count} />
8 changes: 3 additions & 5 deletions src/esbuild_plugins/resolve_svelte_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ const svelte_internal = await fetch(
);
const svelte_internal_src = await svelte_internal.text();

const filter = /^svelte\/internal$/;

export const resolve_svelte_internal: Plugin = {
name: "svelte/internal",
setup(build) {
build.onResolve({ filter }, () => {
build.onResolve({ filter: /^svelte(\/internal)?$/ }, () => {
return {
path: "svelte/internal",
namespace: "fs-virtual",
namespace: "svelte",
external: false,
};
});

build.onLoad({ filter }, () => {
build.onLoad({ filter: /.*/, namespace: "svelte" }, () => {
return {
contents: svelte_internal_src,
};
Expand Down

0 comments on commit 6bcc110

Please sign in to comment.