我使用Prismic.io作为 CMS 并在getInitialProps()
获取这些数据。 内容已预先格式化为 HTML,因此我使用的是dangerouslySetInnerHTML
。
在服务器和客户端上执行时, render()
的输出是相同的。
render()
在服务器端输出错误,与客户端不匹配。
不同之处在于内容在服务器上没有正确的样式,因为 DOM 节点没有正确嵌套。
const htmlFor = (type) => ({__html: this.props[type]})
<Article heading="Devotional" html={true} >
{htmlFor('devotional')}
</Article>
和
const Article = ({heading, children, date, link, style, html}) => (
<article
className="mv3 mv4-m mv5-l measure"
style={style}
>
<header>
<h1 className="f3 f2-ns mt0 lh-title i garamond bb bw3 b--gold">
{heading}
</h1>
</header>
{ html
? <p className="lh-copy" dangerouslySetInnerHTML={children} />
: <p className="lh-copy" >{children}</p>
}
<footer>
{ date
? <p className="f6 i">{date}</p>
: null
}
{link
? <a href="#" className='link dim mid-gray bb b--gold'>
{link}
</a>
: null
}
</footer>
</article>
)
此部署和/_src
在此处公开: https :
@flybayer感谢您的报告。 我可能是错的,但是通过 HTML 验证器传递你的 sith 会给我这个错误https://validator.w3.org/nu/?doc=https%3A%2F%2Fthefaithnet-ynikfpghwu.now.sh%2F我认为是因为在 HTML 中嵌套p
标签无效。 您可以尝试使用 div 而不是外部p
吗?
@impronunciable哇,就是这样!
很好的捕获,非常感谢您的帮助!
很高兴它起作用了!
2016 年 11 月 6 日星期日上午 11:57 Brandon Bayer通知@ github.com
写道:
@impronunciable https://github.com/impronunciable哇,就是这样!
很好的捕获,非常感谢您的帮助!
—
你收到这个是因为你被提到了。直接回复本邮件,在GitHub上查看
https://github.com/zeit/next.js/issues/213#issuecomment -258693902,或者静音
线程
https://github.com/notifications/unsubscribe-auth/AAKHp5EvRuw2GOjOViKL0MjKr0Vrt65sks5q7gbtgaJpZM4KqaPT
.
最有用的评论
@flybayer感谢您的报告。 我可能是错的,但是通过 HTML 验证器传递你的 sith 会给我这个错误https://validator.w3.org/nu/?doc=https%3A%2F%2Fthefaithnet-ynikfpghwu.now.sh%2F我认为是因为在 HTML 中嵌套
p
标签无效。 您可以尝试使用 div 而不是外部p
吗?