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

[Bug] umi3, 开启SSR后,小内容是正常的,现在接口内容过多时,渲染失败 #12731

Closed
1089109 opened this issue Oct 9, 2024 · 1 comment

Comments

@1089109
Copy link

1089109 commented Oct 9, 2024

接口内容返回有37764,已经渲染失败了

content-length: 37764

umi版本

"umi": "3.4.25"

现在测试到的是,其它页面是正常打开的,只有内容过多时才会失败

渲染失败的地址

http://www.huangcy.com/course/chapter/detail?chapterId=151&courseId=82

成功的地址

http://www.huangcy.com/course/chapter/detail?chapterId=150&courseId=82

页面请求接口的地方

 现在控制台只输出5555 web

const CourseDetail = (props: CourseDetailProps) => {
return


hello

}

CourseDetail.getInitialProps = (async ({ isServer, store, history }) => {
if (!isServer) return;
console.log(11111, 'web')
......
console.log(5555, 'web')
const { data: currentChapter } = await getChapterDetail({ id: Number(chapterId), isServer }).catch(err => {
console.log('errror ?', err )
});
console.log(4444, 'web')
let detailData: Course.CourseRule | null = null
if (success && data) {
detailData = data;
}
let content = ''; // 章节内容
let headerLinks = ''; // 将li 改成a链接

console.log(1)
console.log(currentChapter, 'currentChapter')
console.log(2)
// 右侧的索引目录修改
if (currentChapter) {
  content = currentChapter.content;
  content = setContentHeader(currentChapter.content, currentChapter.headerContent);
  headerLinks = setHeaderLink(currentChapter.headerContent);
}
console.log(3)


// 右侧的最多浏览文章/最多评论文章...
const { data: newInfo } = await getMaxArticle({
  current: 1,
  pageSize: 20,
  isBrowse: true,
  isNewArticle: true,
  isComment: true,
  isServer,
});

const {
  newArticleList = [],
  browseList = [],
  commentList = [],
} = newInfo as Classify.ArticleMaxRule;

return Promise.resolve({
  detailData,
  global,
  currentChapter,
  content,
  headerLinks,
  chapterId,
  newArticleList,
  browseList,
  commentList,
})

}) as IGetInitialProps;

server.js

`const Koa = require('koa');
const compress = require('koa-compress');
const mount = require('koa-mount');
const { join, extname } = require('path');
const { parseCookie, parseNavLang } = require('./serverHelper');
const port = 8020; // 端口
const root = join(__dirname, 'dist');

const app = new Koa();
app.use(
compress({
threshold: 1024,
gzip: {
flush: require('zlib').constants.Z_SYNC_FLUSH,
},
deflate: {
flush: require('zlib').constants.Z_SYNC_FLUSH,
},
br: false, // 禁用br解决https gzip不生效加载缓慢问题
}),
);

let render;
app.use(async (ctx, next) => {
/**

  • 扩展global对象
  • 这里是在服务端处理好cookie,
  • 会把所有cookie处理成{}形式
  • 赋值到global上面,方便客户端使用
  • 同时获取浏览器的默认语言,处理好
    */
    global._cookies = parseCookie(ctx);
    global._navigatorLang = parseNavLang(ctx);

const ext = extname(ctx.request.path);

// 符合要求的路由才进行服务端渲染,否则走静态文件逻辑
if (!ext || ext === '.html') {
if (!render) {
render = require('./dist/umi.server');
}
// 这里默认是字符串渲染
ctx.type = 'text/html';
ctx.status = 200;
const { html, error } = await render({
path: ctx.request.url,
mode: 'stream',
});
if (error) {
console.log('----------------服务端报错-------------------', error);
}
ctx.body = html;
} else {
await next();
}
});

app.use(mount('/dist', require('koa-static')(root)));

app.listen(port, () => {
console.log(SSR服务启动成功 http://localhost:${port} 真实接口在80上,由于csr需要代理api接口);
});

module.exports = app.callback();
`

Copy link

github-actions bot commented Oct 9, 2024

由于缺乏足够的信息,我们暂时关闭了该 Issue。请修改(不要回复) Issue 提供最小重现以重新开启。谢谢。

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
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

1 participant