Open TuzSeRik opened 1 year ago
What happens if you change it to
<script>
let editorRef = null;
...
holder: editorRef,
...
</script>
<div bind:this={editorRef} class="editor"></div>
? It works quite well for me with Sveltekit
```Svelte
```What happens if you change it to
<script> let editorRef = null; ... holder: editorRef, ... </script> <div bind:this={editorRef} class="editor"></div>
? It works quite well for me with Sveltekit
Full example
Nothing happens really. The text still duplicates.
@TuzSeRik Thiserror occurs because there is no window object abailable during ssr, as the window object only exists in the browser. Therefore, when preforming ssr, we need to use dynamic import to delay loading Editor.js This code is work for me.
<script lang="ts">
import { onMount } from 'svelte';
let editor: any;
onMount(async () => {
const EditorJS = await import('@editorjs/editorjs');
editor = new EditorJS.default({
holder: 'editor',
placeholder: 'Type something...',
tools: {} // Add your tools here
});
});
</script>
<div id="editor"></div>
@TuzSeRik Thiserror occurs because there is no window object abailable during ssr, as the window object only exists in the browser. Therefore, when preforming ssr, we need to use dynamic import to delay loading Editor.js This code is work for me.
<script lang="ts"> import { onMount } from 'svelte'; let editor: any; onMount(async () => { const EditorJS = await import('@editorjs/editorjs'); editor = new EditorJS.default({ holder: 'editor', placeholder: 'Type something...', tools: {} // Add your tools here }); }); </script> <div id="editor"></div>
I'll try your solution, but I should notice, that I use adapter-static for SPA experience, not SSR
@TuzSeRik Thiserror occurs because there is no window object abailable during ssr, as the window object only exists in the browser. Therefore, when preforming ssr, we need to use dynamic import to delay loading Editor.js This code is work for me.
<script lang="ts"> import { onMount } from 'svelte'; let editor: any; onMount(async () => { const EditorJS = await import('@editorjs/editorjs'); editor = new EditorJS.default({ holder: 'editor', placeholder: 'Type something...', tools: {} // Add your tools here }); }); </script> <div id="editor"></div>
I can confirm that your solution works well for me @ddy-ddy . I did almost the same, except I didn't know about the import() function 🙂
the same happens in nuxt 3, it looks like the only way is to call destroy() and re-instantiate the editor.
Thanks @ddy-ddy. Did you also manage to import editor-js/image
using SvelteKit? I am posing here instead of in that repo because it seems to be abandoned. Following your approach:
<script lang="ts">
import { onMount } from 'svelte';
let editor: any;
onMount(async () => {
const EditorJS = await import('@editorjs/editorjs');
const ImageTool = await import('@editorjs/image');
editor = new EditorJS.default({
holder: 'editor',
placeholder: 'Type something...',
tools: {
image: {
class: ImageTool,
config: {
endpoints: {
byFile: '/api/uploadImage', // Your image upload endpoint
byUrl: '/api/fetchUrl', // Your image upload endpoint
}
}
}
}
});
});
</script>
This approach creates multiple errors on the browser console with the Editor not rendering.
i was plaing around it and it works fine to me
<script lang="ts">
import { onMount } from 'svelte';
let editor: any;
onMount(async () => {
const EditorJS = await import('@editorjs/editorjs');
const Header = (await import('@editorjs/editorjs')).default; // this way it will works (from taxonomy shadcn)
editor = new EditorJS.default({
holder: 'editor',
placeholder: 'Type something...',
tools: {
header: Header,
}
});
});
</script>
<div id="editor"></div>
Editor.js instance renders the same data from 1 to 3 times, when used with Svelte && SvelteKit.
Steps to reproduce:
Create Editor.svelte component to house Editor.js instance