Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在next中使用时会报服务端渲染错误,Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering. #104

Open
virtualflase opened this issue Jun 15, 2023 · 2 comments

Comments

@virtualflase
Copy link

image
image
package版本{
"hox": "2.0.0-rc.0",
"next": "13.4.4",
}
还没开始配置store,请问该组件是不支持在next上使用吗

@Tzxhy
Copy link

Tzxhy commented Sep 20, 2023

发现一个临时解决办法:

新增一个组件:

import {
    PropsWithChildren,
    useEffect,
    useState,
} from 'react'

export default function ClientRunWrapper({children}: PropsWithChildren) {
    const [show, setShow] = useState(false);
    
    useEffect(() => {
        setShow(true);
    }, [])

    if (!show) {
        return null;
    }
    return children;
}

用此组件包裹使用了 hox 的顶层组件,如:

"use client"
import ClientWrapper from "@/components/ClientWrapper";
export default function Page() {
    return <div style={{
        height: '100%',
        padding: 16,
        backgroundColor: '#fff',
        overflow: 'auto',
    }}>
        <ClientWrapper>
            <TableContent />
        </ClientWrapper>
    </div>
}

这样,next dev 会报错,但是可以执行next build了。(否则next build都会失败)

@virtualflase
Copy link
Author

发现一个临时解决办法:

新增一个组件:

import {
    PropsWithChildren,
    useEffect,
    useState,
} from 'react'

export default function ClientRunWrapper({children}: PropsWithChildren) {
    const [show, setShow] = useState(false);
    
    useEffect(() => {
        setShow(true);
    }, [])

    if (!show) {
        return null;
    }
    return children;
}

用此组件包裹使用了 hox 的顶层组件,如:

"use client"
import ClientWrapper from "@/components/ClientWrapper";
export default function Page() {
    return <div style={{
        height: '100%',
        padding: 16,
        backgroundColor: '#fff',
        overflow: 'auto',
    }}>
        <ClientWrapper>
            <TableContent />
        </ClientWrapper>
    </div>
}

这样,next dev 会报错,但是可以执行next build了。(否则next build都会失败)

这样不就是不要ssr吗,我最后还是换了个组件,毕竟这样的话直接不用next会更好o(╥﹏╥)o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants