Skip to content

Commit

Permalink
refactor(ssr): remove ssr-provider & use new hook from @css-render/vu…
Browse files Browse the repository at this point in the history
…e3-ssr
  • Loading branch information
07akioni committed Jun 12, 2021
1 parent 832c759 commit 97bc288
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 384 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@
"vite": "^2.1.3"
},
"dependencies": {
"@css-render/plugin-bem": "^0.15.2",
"@css-render/vue3-ssr": "^0.15.2",
"@css-render/plugin-bem": "^0.15.3",
"@css-render/vue3-ssr": "^0.15.3",
"@types/lodash": "^4.14.170",
"@types/lodash-es": "^4.17.4",
"async-validator": "^3.5.1",
"css-render": "^0.15.2",
"css-render": "^0.15.3",
"date-fns": "^2.19.0",
"evtd": "^0.2.2",
"highlight.js": "^11.0.1",
Expand Down
27 changes: 10 additions & 17 deletions playground/ssr/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h, defineComponent, ref } from 'vue'
import { NButton, NSsrProvider } from 'naive-ui'
import { NButton } from 'naive-ui'

const App = defineComponent({
setup () {
Expand All @@ -8,22 +8,15 @@ const App = defineComponent({
}
},
render () {
return h(
NSsrProvider,
{
ssr: typeof window === 'undefined'
},
{
default: () =>
h(
NButton,
{
onClick: () => this.count++
},
{ default: () => this.count }
)
}
)
return [
h(
NButton,
{
onClick: () => this.count++
},
{ default: () => this.count }
)
]
}
})

Expand Down
6 changes: 5 additions & 1 deletion playground/ssr/pre-build.sh
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
./../../scripts/pre-build-site/pre-build-site.sh
# make sure cwd is the sh's dir

cd ./../../

./scripts/pre-build-site/pre-build-site.sh
9 changes: 9 additions & 0 deletions playground/ssr/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
You need to install `webpack` & `webpack-cli` globally.

```
./pre-build.sh
./build.sh
node dist/server.js
# browse localhost:8086
```
6 changes: 3 additions & 3 deletions src/_mixins/use-rtl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ref, onBeforeMount, inject, watchEffect, computed } from 'vue'
import { ssrInjectionKey } from '../ssr/context'
import { Ref, onBeforeMount, watchEffect, computed } from 'vue'
import { useSsrAdapter } from '@css-render/vue3-ssr'
import {
RtlEnabledState,
RtlItem
Expand All @@ -15,7 +15,7 @@ export default function useRtl (
clsPrefixRef: Ref<string>
): Ref<RtlItem | undefined> | undefined {
if (!rtlStateRef) return undefined
const ssrAdapter = inject(ssrInjectionKey, undefined)
const ssrAdapter = useSsrAdapter()
const componentRtlStateRef = computed(() => {
const { value: rtlState } = rtlStateRef
if (!rtlState) {
Expand Down
6 changes: 3 additions & 3 deletions src/_mixins/use-style.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CNode } from 'css-render'
import { Ref, onBeforeMount, inject } from 'vue'
import { Ref, onBeforeMount } from 'vue'
import { useSsrAdapter } from '@css-render/vue3-ssr'
import globalStyle from '../_styles/global/index.cssr'
import { ssrInjectionKey } from '../ssr/context'
import { throwError } from '../_utils'

export default function useStyle (
Expand All @@ -13,7 +13,7 @@ export default function useStyle (
if (__DEV__) throwError('use-style', 'No style is specified.')
return
}
const ssrAdapter = inject(ssrInjectionKey, undefined)
const ssrAdapter = useSsrAdapter()
const mountStyle = (): void => {
const clsPrefix = clsPrefixRef?.value
style.mount({
Expand Down
4 changes: 2 additions & 2 deletions src/_mixins/use-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
PropType
} from 'vue'
import { merge } from 'lodash-es'
import { useSsrAdapter } from '@css-render/vue3-ssr'
import globalStyle from '../_styles/global/index.cssr'
import { CNode } from 'css-render'
import type { GlobalTheme } from '../config-provider'
import { configProviderInjectionKey } from '../config-provider/src/ConfigProvider'
import type { ThemeCommonVars } from '../_styles/common'
import { ssrInjectionKey } from '../ssr/context'

export interface Theme<N, T = {}, R = any> {
name: N
Expand Down Expand Up @@ -91,7 +91,7 @@ function useTheme<N, T, R> (
props: UseThemeProps<Theme<N, T, R>>,
clsPrefixRef?: Ref<string | undefined>
): ComputedRef<MergedTheme<Theme<N, T, R>>> {
const ssrAdapter = inject(ssrInjectionKey, undefined)
const ssrAdapter = useSsrAdapter()
if (style) {
const mountStyle = (): void => {
const clsPrefix = clsPrefixRef?.value
Expand Down
1 change: 0 additions & 1 deletion src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export * from './skeleton'
export * from './slider'
export * from './space'
export * from './spin'
export * from './ssr'
export * from './statistic'
export * from './steps'
export * from './switch'
Expand Down
17 changes: 0 additions & 17 deletions src/ssr/SsrProvider.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions src/ssr/context.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/ssr/index.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/ssr/tests/SsrProvider.spec.ts

This file was deleted.

Loading

0 comments on commit 97bc288

Please sign in to comment.