Server render writes style="" for an empty style object
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, typescript
- 领域
- web-dev
调研方向
Start with styleToString and attrToHtml in the server rendering code, which decide when a style attribute is written. Add the skip for true, false and '', and omit the attribute when nothing renders. Add the failing case to tests/ssr.test.tsx, then run pnpm test:ci. The size budget also needs SSR_STYLE_SIZE_ALLOWANCE in scripts/size-check.mjs approved by a maintainer before the change can merge.
由索引模型根据 Issue 内容生成。
描述
renderToString(<div style={{}} />) returns <div style=""></div>; React returns <div></div>. Under a CSP without 'unsafe-inline' for styles, the browser reports each empty style="" as a violation.
Redact also writes style values that React skips:
style |
React 19.3.1 | Redact main |
|---|---|---|
{} |
<div></div> |
<div style=""></div> |
{ color: true } |
<div></div> |
<div style="color:true;"></div> |
{ color: '' } |
<div></div> |
<div style="color:;"></div> |
{ color: 'red', width: '' } |
<div style="color:red"></div> |
<div style="color:red;width:;"></div> |
React's pushStyleAttribute skips null, boolean and '' values, and writes style=" only before the first value that renders (react-dom-server.node.development.js:1186, react-dom 19.3.1).
Fix
Branch with the fix and tests, ready to merge (I can't open a PR here): https://github.com/TanStack/redact/compare/main...WolfieLeader:redact:fix/ssr-empty-style
What changes
styleToStringskipstrue,falseand''as well asnullandundefined.attrToHtmlwrites nostyleattribute when nothing renders.
Size
redact/server grows 18 B gzip in source and 16 B built, 7 B and 4 B over its budget. SSR_STYLE_SIZE_ALLOWANCE in scripts/size-check.mjs holds that measured increment and needs your approval. An empty-attribute-only fix still goes 2 B over in source.
Testing
- The new case in
tests/ssr.test.tsxfails onmainand passes with the fix. pnpm test:cipasses on Node 24.22.0.
- 主要语言
- TypeScript
- 星标
- 640
- 派生
- 32
- 平均合并
- 1 小时 15 分钟
- 30 天内合并 PR
- 7
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/redact 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
bug data-types
难度 2/5 1-3 小时 新手友好度 88/100
ClickHouse/clickhouse-js#1293 ·
维护者通常 1 天内回复
-
area: middleware enhancement good first issue
难度 2/5 1-3 小时 新手友好度 68/100
-
agent/quality testing
难度 1/5 1 小时以内 新手友好度 95/100
维护者通常 1 天内回复
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
juspay/agent-distro#203 ·
维护者通常 1 天内回复