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

SSR 支持额外透传 Server 端的数据 #5987

Closed
chenjun1011 opened this issue Feb 28, 2023 · 0 comments · Fixed by #5950
Closed

SSR 支持额外透传 Server 端的数据 #5987

chenjun1011 opened this issue Feb 28, 2023 · 0 comments · Fixed by #5950
Labels

Comments

@chenjun1011
Copy link
Collaborator

Summary | 概述

希望能在调用 Server 端构建产物的时候,透传一部分全局数据。

Motivation | 背景

目前,从 Server 端透传数据,只支持 defineServerDataLoader 的方式,然而实际业务场景下,可能会需要在调用 render 的时候就额外传入一些数据,供应用消费。比如一体化应用透传 env 的例子:

现在的实现是在完成 html 渲染后,再动态插入

image

这种方式不够直观,并且在 流式渲染的情况下,也无法劫持做修改。

类似这类数据,让每个业务在 defineServerDataLoader 确实也不太合理

因此,希望能开放一部分透传 Server 端数据的能力。

Usage example | 使用示例

No response

Detailed design | 方案设计

如下图所示,在调用 Server Render 时候,通过 serverData 透传数据

await serverModule.renderToResponse(ctx, {
  documentOnly,
  basename,
  serverData: {
    env: 'pre'
  }
});

使用数据:

import { useAppContext } from '@ice/runtime';

const appContext = useAppContext();
const { serverData } = appContext;

Additional context | 额外信息

No response

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

Successfully merging a pull request may close this issue.

1 participant