Skip to content

Commit

Permalink
fix!: lazy load live mode (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan authored Nov 8, 2023
1 parent 1982518 commit e52991c
Show file tree
Hide file tree
Showing 26 changed files with 415 additions and 445 deletions.
2 changes: 1 addition & 1 deletion apps/next/src/app/shoes/VisualEditing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function VisualEditing() {
}
}, [pathname, searchParams])

useLiveMode()
useLiveMode({ allowStudioOrigin: studioUrl })

return null
}
5 changes: 1 addition & 4 deletions apps/next/src/app/shoes/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@ const client = createClient({
},
})

export const { useQuery, useLiveMode } = createQueryStore({
client,
allowStudioOrigin: studioUrl,
})
export const { useQuery, useLiveMode } = createQueryStore({ client })
2 changes: 1 addition & 1 deletion apps/next/src/components/VisualEditing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function VisualEditing() {
router?.replace,
])

useLiveMode()
useLiveMode({ allowStudioOrigin: studioUrl })

return null
}
6 changes: 1 addition & 5 deletions apps/nuxt/composables/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { createQueryStore } from '@sanity/nuxt-loader'
import { studioUrl } from 'apps-common/env'
import { getClient } from '@/utils'

const client = getClient()

export const { useQuery, useLiveMode } = createQueryStore({
client,
allowStudioOrigin: studioUrl,
})
export const { useQuery, enableLiveMode } = createQueryStore({ client })
8 changes: 6 additions & 2 deletions apps/nuxt/pages/shoes/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import { studioUrl, workspaces } from 'apps-common/env'
import { formatCurrency } from 'apps-common/utils'
import { shoesList, type ShoesListResult } from 'apps-common/queries'
import { urlFor, urlForCrossDatasetReference } from '~/utils'
import { useQuery, useLiveMode } from '~/composables/useQuery'
import { useQuery, enableLiveMode } from '~/composables/useQuery'
import { vSanity, wrapData, unwrapData } from '@sanity/nuxt-loader/directive'
const { data, sourceMap, loading } = useQuery<ShoesListResult>(shoesList)
Expand All @@ -121,7 +121,11 @@ const products = computed(() => {
)
})
let disableLiveMode: ReturnType<typeof enableLiveMode> | undefined
onMounted(() => {
useLiveMode()
disableLiveMode = enableLiveMode({
allowStudioOrigin: studioUrl,
})
})
onUnmounted(() => disableLiveMode())
</script>
1 change: 0 additions & 1 deletion apps/page-builder-demo/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import withBundleAnalyzer from '@next/bundle-analyzer'

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
experimental: {
logging: {
level: 'verbose',
Expand Down
2 changes: 1 addition & 1 deletion apps/page-builder-demo/src/app/VisualEditing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function VisualEditing() {
}
}, [pathname, searchParams])

useLiveMode()
useLiveMode({ allowStudioOrigin: studioUrl })

return null
}
2 changes: 1 addition & 1 deletion apps/remix/app/VisualEditing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function VisualEditing() {
}
}, [location.hash, location.pathname, location.search])

useLiveMode()
useLiveMode({ allowStudioOrigin: studioUrl })

return null
}
6 changes: 1 addition & 5 deletions apps/remix/app/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { createQueryStore } from '@sanity/react-loader'
import { studioUrl } from 'apps-common/env'
import { getClient } from '~/utils'

const client = getClient()

export const { query, useQuery, useLiveMode } = createQueryStore({
client,
allowStudioOrigin: studioUrl,
})
export const { query, useQuery, useLiveMode } = createQueryStore({ client })
5 changes: 3 additions & 2 deletions apps/remix/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
],
"compilerOptions": {
"skipLibCheck": true,
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"lib": ["DOM", "DOM.Iterable", "ES2020"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"target": "ES2019",
"target": "ES2020",
"module": "ES2020",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
Expand Down
4 changes: 2 additions & 2 deletions package.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { defineConfig } from '@sanity/pkg-utils'
export default defineConfig({
minify: false,
extract: {
bundledPackages: ['channels', 'visual-editing-helpers', '@sanity/util'],
bundledPackages: ['channels', 'visual-editing-helpers'],
rules: {
'ae-forgotten-export': 'warn',
'ae-incompatible-release-tags': 'warn',
'ae-missing-release-tag': 'warn',
'ae-internal-missing-underscore': 'off',
'ae-missing-release-tag': 'warn',
},
},
tsconfig: 'tsconfig.build.json',
Expand Down
Loading

5 comments on commit e52991c

@vercel
Copy link

@vercel vercel bot commented on e52991c Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visual-editing-studio – ./apps/studio

visual-editing-studio.sanity.build
visual-editing-studio-git-main.sanity.build

@vercel
Copy link

@vercel vercel bot commented on e52991c Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visual-editing-remix – ./apps/remix

visual-editing-remix.sanity.build
visual-editing-remix-git-main.sanity.build

@vercel
Copy link

@vercel vercel bot commented on e52991c Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visual-editing-svelte – ./apps/svelte

visual-editing-svelte.sanity.build
visual-editing-svelte-git-main.sanity.build

@vercel
Copy link

@vercel vercel bot commented on e52991c Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visual-editing-page-builder-demo – ./apps/page-builder-demo

visual-editing-page-builder-demo-git-main.sanity.build
visual-editing-page-builder-demo.sanity.build

@vercel
Copy link

@vercel vercel bot commented on e52991c Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

visual-editing-nuxt – ./apps/nuxt

visual-editing-nuxt-git-main.sanity.build
visual-editing-nuxt.sanity.build

Please sign in to comment.