This repository was archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 984
feat(nuxt): experimental server component islands #5689
Merged
Merged
Changes from all commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
6e3d7e9
refactor: split out renderMeta into separate function
danielroe 488d3ba
feat: support rendering individual components
danielroe aa98041
feat: render styles/scripts and extract type
danielroe 109d48a
fix: workaround upstream vue issue
danielroe 7547e03
fix: suppress vue-router warning
danielroe fdb09e2
feat: support POST requests as well
danielroe 12d2592
refactor: use `destr` to parse
danielroe be7ab20
refactor: clarity
danielroe 4759e41
fix: remove setHeader for `application/json`
danielroe 8d6e23a
refactor: styles & scripts
danielroe 4a1db3b
feat: add `isIndividualRender` composable
danielroe b1c32db
feat: support passing url in `customRender` payload
danielroe 11c8e14
test: add test suite for server rendering individual components
danielroe f832468
test: improve snapshot readability
danielroe 63978b4
chore: revert changes
danielroe be889e8
fix: disable universal router too
danielroe 685fc4b
refactor: remove `isIndividualRender` and detect directly from app flag
danielroe 08b8274
fix: use based on url
danielroe 5696fd8
test: update state snapshots
danielroe 9bb09f7
Merge branch 'main' into feat/selective-rendering
pi0 f180149
revert back json header
pi0 4a8e5f9
fix: always repond json in custom render mode
pi0 cc273c3
refactor: rename to isolated
pi0 206469f
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe eb889fa
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe 0efce9a
refactor: only render island components (via `~/components/islands` oβ¦
danielroe e712bd2
test: update components fixture for global + islands components
danielroe 4fe0bf5
feat: strip server-only component code from client build
danielroe 192ff02
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe 0a96bb5
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe 9ff0f7d
Merge branch 'main' into feat/selective-rendering
danielroe bf458c1
refactor: return `RenderResponse` for components too, remove nuxt hooβ¦
danielroe ea7e9ba
Merge branch 'main' into feat/selective-rendering
pi0 54300ff
isolated ~> island
pi0 e18942a
refactor: use single render endpoint
pi0 33858ed
Merge branch 'main' into feat/selective-rendering
pi0 9e18a88
fix lint and update test
pi0 8b8fa7a
update
pi0 d610fbb
update types
pi0 1cb6406
remove server-components plugin
pi0 b41bb84
add render:island hook
pi0 66d61fa
improved url format for caching and prerendering
pi0 6f8a2d9
handle 404 components
pi0 5372a87
feat: `NuxtIsland` component
pi0 7cad463
chore: remove unused imports
pi0 752dfc0
nullify island renderer for client-side
pi0 2891b0b
improve url matching
pi0 71a0c88
fix hashId matching
pi0 d5b8c1e
update tests
pi0 8994268
use NuxtIslandContext for nuxt app
pi0 3956bfb
refactor: reduce git diff
pi0 1101eba
fix: add name to hashId to make it always unique
pi0 340f858
update snapshot test
pi0 811c193
fix: split component islands
pi0 5d15708
nuxt-island: test client side and handle parallel requests to same
pi0 82e919c
remove comments from snapshot
pi0 b2fcd74
Merge branch 'main' into feat/selective-rendering
pi0 c2a723f
refactor: move tag parsing to the server renderer
pi0 4d10638
fix: strip all comments
pi0 b363043
update test
pi0 4a8fb3d
fix tag parsing and compress
pi0 22dfbcd
use computed object for head
pi0 aa7e07a
eslint is sometimes not funny either
pi0 d41fd7a
update fixture
pi0 dc7db7f
chore: typo
danielroe 410beda
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe 2dce064
fix: respect island url
danielroe bbb12e4
test: remove hashes
danielroe ae18933
style: revert indent
danielroe 1d98c28
test: add support for extracting style/title tags
danielroe 96d1648
fix: type assertion
danielroe dd09120
style: reorder import
danielroe 734bfcc
style: move comment
danielroe bd3e3d4
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe 7cb15e7
test: sort after map
danielroe d7f810d
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe 3334dbd
Merge remote-tracking branch 'origin/main' into feat/selective-rendering
danielroe de7d997
test: update snapshot
danielroe ee495e3
Merge branch 'main' into feat/selective-rendering
pi0 33c2658
small fixes
pi0 7c66c41
feat: implement style inlining with unique keys
pi0 2484081
debug test
pi0 3be020c
enable behind `experimental.componentIslands`
pi0 b25019b
Merge branch 'main' into feat/selective-rendering
pi0 24ea58d
try to normalize head for dev
pi0 73f6bb5
add fallback for components.islands.mjs when disabled
pi0 dfaaf6d
Merge branch 'main' into feat/selective-rendering
pi0 e1148a4
rest: mask data-v- id
pi0 3529f0c
Merge branch 'main' into feat/selective-rendering
pi0 3a65a8d
fix missing key type
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,33 @@ | ||
| import { createBlock, defineComponent, h, Teleport } from 'vue' | ||
|
|
||
| // @ts-ignore | ||
| import * as islandComponents from '#build/components.islands.mjs' | ||
| import { createError } from '#app' | ||
|
|
||
| export default defineComponent({ | ||
| props: { | ||
| context: { | ||
| type: Object as () => { name: string, props?: Record<string, any> }, | ||
| required: true | ||
| } | ||
| }, | ||
| async setup (props) { | ||
| // TODO: https://github.com/vuejs/core/issues/6207 | ||
| const component = islandComponents[props.context.name] | ||
|
|
||
| if (!component) { | ||
| throw createError({ | ||
| statusCode: 404, | ||
| statusMessage: `Island component not found: ${JSON.stringify(component)}` | ||
| }) | ||
| } | ||
|
|
||
| if (typeof component === 'object') { | ||
| await component.__asyncLoader?.() | ||
| } | ||
|
|
||
| return () => [ | ||
| createBlock(Teleport as any, { to: 'nuxt-island' }, [h(component || 'span', props.context.props)]) | ||
| ] | ||
| } | ||
| }) |
This file contains hidden or 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,67 @@ | ||
| import { defineComponent, createStaticVNode, computed, ref, watch } from 'vue' | ||
| import { debounce } from 'perfect-debounce' | ||
| import { hash } from 'ohash' | ||
| import type { MetaObject } from '@nuxt/schema' | ||
| // eslint-disable-next-line import/no-restricted-paths | ||
| import type { NuxtIslandResponse } from '../../core/runtime/nitro/renderer' | ||
| import { useHead, useNuxtApp } from '#app' | ||
|
|
||
| const pKey = '_islandPromises' | ||
|
|
||
| export default defineComponent({ | ||
| name: 'NuxtIsland', | ||
| props: { | ||
| name: { | ||
| type: String, | ||
| required: true | ||
| }, | ||
| props: { | ||
| type: Object, | ||
| default: () => undefined | ||
| }, | ||
| context: { | ||
| type: Object, | ||
| default: () => ({}) | ||
| } | ||
| }, | ||
| async setup (props) { | ||
| const nuxtApp = useNuxtApp() | ||
| const hashId = computed(() => hash([props.name, props.props, props.context])) | ||
| const html = ref<string>('') | ||
| const cHead = ref<MetaObject>({ link: [], style: [] }) | ||
| useHead(cHead) | ||
|
|
||
| function _fetchComponent () { | ||
| // TODO: Validate response | ||
| return $fetch<NuxtIslandResponse>(`/__nuxt_island/${props.name}:${hashId.value}`, { | ||
| params: { | ||
| ...props.context, | ||
| props: props.props ? JSON.stringify(props.props) : undefined | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| async function fetchComponent () { | ||
| nuxtApp[pKey] = nuxtApp[pKey] || {} | ||
| if (!nuxtApp[pKey][hashId.value]) { | ||
| nuxtApp[pKey][hashId.value] = _fetchComponent().finally(() => { | ||
| delete nuxtApp[pKey][hashId.value] | ||
| }) | ||
| } | ||
| const res: NuxtIslandResponse = await nuxtApp[pKey][hashId.value] | ||
| cHead.value.link = res.head.link | ||
| cHead.value.style = res.head.style | ||
| html.value = res.html | ||
| } | ||
|
|
||
| if (process.server || !nuxtApp.isHydrating) { | ||
| await fetchComponent() | ||
| } | ||
|
|
||
| if (process.client) { | ||
| watch(props, debounce(fetchComponent, 100)) | ||
| } | ||
|
|
||
| return () => createStaticVNode(html.value, 1) | ||
| } | ||
| }) | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.