sapper

How can I fix localStorage error in sapper/svelte

我的梦境 提交于 2021-02-11 04:31:06
问题 import { writable } from 'svelte/store'; /** Read the current token from LocalStorage on boot */ const token = writable(localStorage.getItem('token')); /** Store the token in LocalStorage whenever it´s updated */ token.subscribe((val) => { if (!localStorage) return; if (!val) { return localStorage.removeItem('token'); } localStorage.setItem('token', val); }); export default token; I still get an error that localStorage is undefined in sapper when I run npm run dev 回答1: In Sapper, your code

Emit truly “raw” html in Svelte

前提是你 提交于 2021-02-10 06:53:32
问题 I'm receiving raw html snippets from a headless CMS that I need to render as-is in a Sapper application. This also includes cases where I receive an opening tag and the corresponding closing tag as two pieces of HTML between which I add a Svelte component. <script> import MyComponent from './MyComponent.svelte' // example snippets coming from headless CMS const prefix = '<p class="test">' const suffix = '</p>' </script> <!-- use snippets as-is --> {@html prefix} <MyComponent /> {@html suffix}

Emit truly “raw” html in Svelte

妖精的绣舞 提交于 2021-02-10 06:51:39
问题 I'm receiving raw html snippets from a headless CMS that I need to render as-is in a Sapper application. This also includes cases where I receive an opening tag and the corresponding closing tag as two pieces of HTML between which I add a Svelte component. <script> import MyComponent from './MyComponent.svelte' // example snippets coming from headless CMS const prefix = '<p class="test">' const suffix = '</p>' </script> <!-- use snippets as-is --> {@html prefix} <MyComponent /> {@html suffix}

Sapper/Svelte possible to conditionally import components?

半腔热情 提交于 2021-02-08 06:09:54
问题 In Sapper I am trying to import a component only if being rendered client side (using onMount ). Is there something similar to React Suspense and React.lazy ? Or is there another approach? 回答1: You can certainly do it that way, yes: <script> import { onMount } from 'svelte'; let Thing; onMount(async () => { Thing = (await import('./Thing.svelte')).default; }); </script> <svelte:component this={Thing} answer={42}> <p>some slotted content</p> </svelte:component> Demo here. Alternatively, you

A Sapper-compatible setup to serve multiple apps from a single Express/Polka entry point

五迷三道 提交于 2021-02-07 12:45:15
问题 I need to set up a Polka (or Express) server so that it can serve multiple applications (one per hostname) from a single server.js entry point. It can be done using the vhost middleware (https://github.com/expressjs/vhost). Each app is exported as a middleware, and the one that corresponds to each request is added in the middleware chain in server.js . However, some (not all) of these apps will be Sapper applications so the setup must be compatible with Sapper. So far as I am aware, Sapper

Disable hydration in Sapper

六月ゝ 毕业季﹏ 提交于 2021-01-29 10:15:29
问题 I was testing Sapper and got stuck with complex TweenMax page transitions I'm used to do when working with BarbaJS or HighwayJS, so I'm wondering is there's a way to disable hydration in Sapper so that I can only have the SSR website I can bend to my will. If there's a way, that would be great. 回答1: Sure — just delete the code in src/client.js that starts the app 来源: https://stackoverflow.com/questions/58641735/disable-hydration-in-sapper

Cypress submitting form with preventDefault

左心房为你撑大大i 提交于 2021-01-28 08:53:08
问题 I am having trouble using Cypress. There are 2 problems I'm currently having. A form with preventDefault is being submitted and the page is refreshing. I have to .click() and input before I can .type() into it. -- I have a form that has preventDefault, and you can see from the test that it submites the form, which adds a empty query string to the url, and none of my error handling messages are shown. This doesn't actually happen when I use the app myself. it('requires email', () => { cy.visit

How to persist UI component state data in Sapper?

主宰稳场 提交于 2021-01-28 06:00:49
问题 In a Sapper app, I want to be able to persist the state of some UI components so I can navigate the app without losing state when the user returns to the pages using those components. In a Svelte-only app, this is usually done with a custom store that uses the sessionStorage or localStorage API. A good example of that can be found in R. Mark Volkmann's book Svelte and Sapper in Action , §6.24: store-util.js import {writable} from 'svelte/store'; function persist(key, value) { sessionStorage

How can I manually compile a svelte component down to the final javascript and css that sapper/svelte produces?

谁都会走 提交于 2021-01-24 07:16:41
问题 Our company produces an automation framework that is written in svelte/sapper. One feature is that developers can create custom ui widgets, currently using plain js/html/css and our client side api. These widgets are stored in the database and not on the file system. I think it would be a big plus to allow them to create widgets as svelte components since it contains all of the markup, js and css in one location and would give them all of the benefits of svelte's reactivity. I have gotten as

How can I manually compile a svelte component down to the final javascript and css that sapper/svelte produces?

ε祈祈猫儿з 提交于 2021-01-24 07:14:27
问题 Our company produces an automation framework that is written in svelte/sapper. One feature is that developers can create custom ui widgets, currently using plain js/html/css and our client side api. These widgets are stored in the database and not on the file system. I think it would be a big plus to allow them to create widgets as svelte components since it contains all of the markup, js and css in one location and would give them all of the benefits of svelte's reactivity. I have gotten as