-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description - add test for SSR'ing lazy-loadable components - tweak Sveltekit e2e test to do the above
- Loading branch information
Showing
11 changed files
with
361 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
export const EAGER_DYNAMIC_LOADING_CUSTOM_COMPONENTS = { | ||
ownerId: 'ad30f9a246614faaa6a03374f83554c9', | ||
lastUpdateBy: null, | ||
createdDate: 1727698733481, | ||
id: 'ecb200c7c9954212a276b1071a376f18', | ||
'@version': 4, | ||
name: 'fsafsggxz', | ||
modelId: '17c6065109ef4062ba083f5741f4ee6a', | ||
published: 'published', | ||
meta: { | ||
lastPreviewUrl: | ||
'http://localhost:5173/fsafsggxz?builder.space=ad30f9a246614faaa6a03374f83554c9&builder.user.permissions=read%2Ccreate%2Cpublish%2CeditCode%2CeditDesigns%2Cadmin%2CeditLayouts%2CeditLayers&builder.user.role.name=Admin&builder.user.role.id=admin&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=ecb200c7c9954212a276b1071a376f18&builder.overrides.ecb200c7c9954212a276b1071a376f18=ecb200c7c9954212a276b1071a376f18&builder.overrides.page:/fsafsggxz=ecb200c7c9954212a276b1071a376f18&builder.options.locale=Default', | ||
kind: 'page', | ||
hasLinks: false, | ||
componentsUsed: { | ||
LazyComponent: 1, | ||
}, | ||
}, | ||
priority: -718, | ||
stage: 'b3ee01559a244a078973f545ad475eba', | ||
query: [ | ||
{ | ||
'@type': '@builder.io/core:Query', | ||
property: 'urlPath', | ||
operator: 'is', | ||
value: '/fsafsggxz', | ||
}, | ||
], | ||
data: { | ||
title: 'fsafsggxz', | ||
themeId: false, | ||
blocks: [ | ||
{ | ||
'@type': '@builder.io/sdk:Element', | ||
'@version': 2, | ||
id: 'builder-5a8cdbbf69f14c79a4fa71438c8fd4cf', | ||
component: { | ||
name: 'LazyComponent', | ||
options: {}, | ||
}, | ||
responsiveStyles: { | ||
large: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
position: 'relative', | ||
flexShrink: '0', | ||
boxSizing: 'border-box', | ||
marginTop: '20px', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
metrics: { | ||
clicks: 0, | ||
impressions: 0, | ||
}, | ||
variations: {}, | ||
lastUpdated: 1727704258246, | ||
firstPublished: 1727704258239, | ||
testRatio: 1, | ||
createdBy: 'RuGeCLr9ryVt1xRazFYc72uWwIK2', | ||
lastUpdatedBy: 'RuGeCLr9ryVt1xRazFYc72uWwIK2', | ||
folders: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,7 @@ export async function load({ url }) { | |
_processContentResult, | ||
}); | ||
|
||
return { props }; | ||
return { | ||
props, | ||
}; | ||
} |
18 changes: 1 addition & 17 deletions
18
packages/sdks/e2e/sveltekit/src/routes/[...catchall]/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/sdks/e2e/sveltekit/src/routes/[...catchall]/+page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { browser } from '$app/environment'; | ||
import NotLazyComponent from '../../components/NotLazyComponent.svelte'; | ||
|
||
/** | ||
* Vite/Rollup does not allow arbitrary paths to be dynamic imports. | ||
* https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations | ||
* | ||
* Imports must start with `./` or `../`, so we recommend placing all components in a specific directory, | ||
* and using that to lazy-load the components into Builder. | ||
*/ | ||
const getLazyLoadedComponentImport = (path: string) => | ||
import(`../../components/${path}.svelte`); | ||
|
||
/** | ||
* This helper function guarantees that: | ||
* 1. On the server, the component is loaded eagerly. | ||
* 2. On the client, the component is loaded lazily. | ||
*/ | ||
const getComponentLoader = async (path: string) => { | ||
if (browser) { | ||
return () => getLazyLoadedComponentImport(path); | ||
} else { | ||
const compImport = await getLazyLoadedComponentImport(path); | ||
return () => compImport; | ||
} | ||
}; | ||
|
||
/** @type {import('./$types').PageLoad} */ | ||
export async function load({ data }) { | ||
const lazyImport = await getComponentLoader('LazyComponent'); | ||
return { | ||
...data, | ||
customComponents: [ | ||
{ | ||
name: 'LazyComponent', | ||
component: { | ||
load: lazyImport, | ||
}, | ||
}, | ||
{ | ||
name: 'NotLazyComponent', | ||
component: NotLazyComponent, | ||
}, | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
packages/sdks/overrides/svelte/src/components/awaiter.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
<script lang="ts"> | ||
export let load: () => Promise<any>; | ||
import type { SvelteComponent } from 'svelte'; | ||
export let load: () => Promise<{ default: typeof SvelteComponent<any> }>; | ||
export let fallback: any; | ||
export let props: any; | ||
export let attributes: any; | ||
const componentImport = typeof load === 'string' ? import(load) : load(); | ||
</script> | ||
|
||
{#await load()} | ||
{#await componentImport} | ||
{#if fallback} | ||
<svelte:component this={fallback} /> | ||
{/if} | ||
{:then { default: Component }} | ||
<svelte:component | ||
this={Component} | ||
{...props} | ||
attributes={attributes} | ||
> | ||
{:then { default: Component }} | ||
<svelte:component this={Component} {...props} {attributes}> | ||
<slot /> | ||
</svelte:component> | ||
{/await} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.