fix: components with rtl support throws error in SSR

This commit is contained in:
07akioni 2021-09-25 18:09:18 +08:00
parent 0e6926cef4
commit 698e557797
6 changed files with 32 additions and 3 deletions

View File

@ -11,6 +11,7 @@
- Fix `n-global-style` applies style transition on first mount.
- Fix `n-drawer` border transition, closes[#1211].
- Fix `n-input-number`'s `value` prop can't be `null` type.
- Fix components with rtl support throws error in SSR.
### Feats

View File

@ -11,6 +11,7 @@
- 修复 `n-global-style` 在首次挂载时应用样式过渡
- 修复 `n-drawer` 边界缺少 transition关闭 [#1211]
- 修复 `n-input-number``value` 属性不能为 null 类型
- 修复支持 rtl 的组件 SSR 报错
### Feats

View File

@ -80,7 +80,7 @@
"@vue/compiler-sfc": "^3.0.10",
"@vue/eslint-config-standard": "^6.0.0",
"@vue/eslint-config-typescript": "^7.0.0",
"@vue/server-renderer": "^3.2.12",
"@vue/server-renderer": "^3.2.18",
"@vue/test-utils": "^2.0.0-rc.9",
"autoprefixer": "^10.2.6",
"babel-eslint": "^10.1.0",

View File

@ -31,7 +31,7 @@ export default function useRtl (
// if it already exists, we only need to watch clsPrefix, although in most
// of time it's unnecessary... However we can at least listen less
// handlers, which is great.
if (exists(id)) return
if (exists(id, ssrAdapter)) return
const { value: componentRtlState } = componentRtlStateRef
if (!componentRtlState) return
componentRtlState.style.mount({

View File

@ -0,0 +1,25 @@
/**
* @jest-environment node
*/
import { h, createSSRApp } from 'vue'
import { renderToString } from '@vue/server-renderer'
import { setup } from '@css-render/vue3-ssr'
import { NConfigProvider, NButton } from '../..'
describe('SSR', () => {
it('works', async () => {
const app = createSSRApp(() => (
<NConfigProvider>
{{
default: () => <NButton />
}}
</NConfigProvider>
))
setup(app)
try {
await renderToString(app)
} catch (e) {
expect(e).not.toBeTruthy()
}
})
})

View File

@ -1,2 +1,4 @@
// https://github.com/jsdom/jsdom/issues/1422
HTMLDivElement.prototype.scrollTo = () => {}
if (typeof window !== 'undefined') {
HTMLDivElement.prototype.scrollTo = () => {}
}