Server render writes style="" for an empty style object

オープン
#187 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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
  • styleToString skips true, false and '' as well as null and undefined.
  • attrToHtml writes no style attribute 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.tsx fails on main and passes with the fix.
  • pnpm test:ci passes on Node 24.22.0.
主要言語
TypeScript
スター
640
フォーク
32
平均マージ
1時間 15分
マージ済み PR(30日)
7

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/redact のほかの issue

TanStack/redact の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。