Skip to content

fix: handle missing style container - #811

Merged
yoyo837 merged 2 commits into
react-component:masterfrom
nrps9909:codex/handle-missing-style-container
Sep 20, 2026
Merged

yoyo837 merged 2 commits into
react-component:masterfrom
nrps9909:codex/handle-missing-style-container

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • return null when style injection runs during a transient document state with neither <head> nor <body>
  • guard the updateCSS, removal, and container-sync paths without changing insertion order for valid containers
  • cover both injectCSS and updateCSS with regressions that remove and then restore the document style containers

Closes #603.

Why a new fix

The older #455 exact head (903dfe1) still throws at container.appendChild(styleNode) for both public paths. It also skips insertion for prepend mode when a valid container is empty, because insertBefore(styleNode, null) was replaced with a conditional. This PR keeps the standard empty-container insertion behavior and returns early only when the container itself is absent. I left the exact-head reproduction details on #455.

Verification — September 20, 2026

Follow-up at signed/GitHub-Verified head 0a7b162f207c9f67ba3f90172af861497437f28e.

The failed code checks were Codecov patch/project thresholds: three new guard-return lines lacked coverage. Added public-API regressions for removal while head/body are detached and containers disappearing during style creation, then verified recovery after restoration. Both new cases fail on the pre-fix source. Full run: 30 suites / 201 tests pass, 1 skipped; all changed executable lines in dynamicCSS.ts are covered locally. TypeScript and focused lint/format checks pass. Runtime code is unchanged. Vercel team authorization is a separate upstream gate.

Remote checks for this new commit are separate from the local results above.

AI assistance disclosure

Codex assisted with implementation, conflict resolution, regression tests, and validation.

Summary by CodeRabbit

  • 错误修复
    • 改进页面缺少可用容器时的样式处理稳定性。
    • 注入、更新或移除样式时,即使容器不可用也不会抛出异常。
    • 占位样式同步失败时可安全终止操作。

@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 18ecea0c-c61a-4fb3-86a9-578905bb0172

📥 Commits

Reviewing files that changed from the base of the PR and between dfed9b0 and 0a7b162.

📒 Files selected for processing (1)
  • tests/dynamicCSS.test.tsx

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

本次变更为动态 CSS 操作增加空容器保护。findStylesinjectCSSupdateCSS 在容器缺失时安全返回,removeCSSsyncRealContainer 避免访问空节点。测试覆盖 headbody 同时缺失的场景。

Changes

动态 CSS 容器安全处理

Layer / File(s) Summary
容器与样式节点保护
src/Dom/dynamicCSS.ts
当容器或新样式节点不可用时,相关函数返回空结果或提前结束。删除节点时使用可选链。
缺失容器测试
tests/dynamicCSS.test.tsx
新增测试,验证 headbody 缺失时返回 null、不抛出异常、正确清理,并可在恢复 DOM 后重建样式。

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed PR #811 满足 #603 的编码要求。findStyles 在容器为 null 时返回空数组。injectCSSupdateCSS 在默认容器不可用时返回 nullremoveCSSsyncRealContainer 在容器或占位样式不可用时不会访问空节点。新增测试覆盖 headbody 同时缺失、样式创建期间容器消失、清理路径,以及容…
Out of Scope Changes check ✅ Passed 已审查的源代码和测试改动均围绕 #603 的容器缺失保护、样式同步、清理行为和回归覆盖。未发现与该问题无关的功能、API 或配置改动。
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题“fix: handle missing style container”准确概括了本次变更的主要内容,即处理缺失的样式容器。标题简洁、明确,并与代码和测试变更一致。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

小兔看守空容器,
样式安全不乱跑。
head body 暂离场,
函数安静返 null。
DOM 复原风又轻,
CSS 重建亮晶晶。

Comment @coderabbitai help to get the list of available commands.

@yoyo837

yoyo837 commented Sep 17, 2026

Copy link
Copy Markdown
Member

Rebase please.

@nrps9909
nrps9909 force-pushed the codex/handle-missing-style-container branch from b1d5901 to dfed9b0 Compare September 17, 2026 08:19
@nrps9909

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (c241125); signed/GitHub-Verified head: dfed9b0bc7f3565ece68b416c3455c4ba259b306.

  • Full suite: 30 suites, 199 tests passed; 1 test skipped.
  • TypeScript, ESM/CJS/declaration build, focused ESLint (0 errors), Prettier and diff checks passed.
  • GitHub signatures and changed-file blobs were checked against the local branch.
  • Includes upstream fix: resolve pre-existing test failures on master #815, which fixes the prior pickAttrs and React-17 fallback test failures.
  • Upstream CI: ✅ test currently action_required. A maintainer must approve the fork workflow before it can run.
  • Vercel preview still requires upstream team authorization.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.90%. Comparing base (c241125) to head (0a7b162).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #811      +/-   ##
==========================================
+ Coverage   86.77%   86.90%   +0.13%     
==========================================
  Files          41       41              
  Lines        1096     1107      +11     
  Branches      397      402       +5     
==========================================
+ Hits          951      962      +11     
  Misses        143      143              
  Partials        2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yoyo837

yoyo837 commented Sep 17, 2026

Copy link
Copy Markdown
Member

CI failed.

@nrps9909

nrps9909 commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up at signed/GitHub-Verified head 0a7b162f207c9f67ba3f90172af861497437f28e.

The failed code checks were Codecov patch/project thresholds: three new guard-return lines lacked coverage. Added public-API regressions for removal while head/body are detached and containers disappearing during style creation, then verified recovery after restoration. Both new cases fail on the pre-fix source. Full run: 30 suites / 201 tests pass, 1 skipped; all changed executable lines in dynamicCSS.ts are covered locally. TypeScript and focused lint/format checks pass. Runtime code is unchanged. Vercel team authorization is a separate upstream gate.

CI update: the exact-head test workflow, React Doctor, CodeQL, Surge preview, and both Codecov patch/project checks pass. The only remaining failed status is Vercel team authorization.

@yoyo837
yoyo837 merged commit 90e5fb5 into react-component:master Sep 20, 2026
11 of 12 checks passed
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

Successfully merging this pull request may close these issues.

Cannot read properties of null (reading 'children') - dynamicCSS.ts

2 participants