Skip to content

Commit 60395ea

Browse files
committed
docs: Correct copy/paste mistake in zh v11 'Upgrade Guide'
1 parent 04d7400 commit 60395ea

2 files changed

Lines changed: 14 additions & 87 deletions

File tree

content/zh/guide/v11/upgrade-guide.md

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -203,84 +203,3 @@ type MyCustomButtonProps = ButtonHTMLAttributes & {
203203
/* ... */
204204
};
205205
```
206-
207-
````
208-
209-
### 将数值样式自动添加 `px` 的行为移到 `preact/compat`
210-
211-
Preact 11 已将对数值类型样式属性自动添加 `px` 的逻辑从核心库移动到 `preact/compat`。
212-
213-
```jsx
214-
<h1 style={{ height: 500 }}>Hello World!</h1>
215-
// Preact 10: <h1 style="height:500px">Hello World!</h1>
216-
// Preact 11: <h1 style="height:500">Hello World!</h1>
217-
````
218-
219-
### `defaultProps` 支持移动到 `preact/compat`
220-
221-
由于函数组件与 Hook 的普及,`defaultProps` 使用频率下降,因此该支持已移入 `preact/compat`
222-
223-
### `render()` 中移除 `replaceNode` 参数
224-
225-
`render()` 的第三个(可选)参数在 Preact 11 中被移除,因为该实现存在许多 bug 和边缘情况,且无法很好地满足某些关键用例。
226-
227-
如果你仍然需要此功能,我们提供了一个与 Preact 10 兼容的独立实现:[`preact-root-fragment`](https://github.com/preactjs/preact-root-fragment)
228-
229-
```html
230-
<div id="root">
231-
<section id="widgetA"><h1>Widget A</h1></section>
232-
<section id="widgetB"><h1>Widget B</h1></section>
233-
<section id="widgetC"><h1>Widget C</h1></section>
234-
</div>
235-
```
236-
237-
```jsx
238-
// Preact 10
239-
import { render } from 'preact';
240-
241-
render(<App />, root, widgetC);
242-
243-
// Preact 11
244-
import { render } from 'preact';
245-
import { createRootFragment } from 'preact-root-fragment';
246-
247-
render(<App />, createRootFragment(root, widgetC));
248-
```
249-
250-
### 移除 `Component.base` 属性
251-
252-
我们将移除 `Component.base`,因为暴露组件所连接的 DOM 总显得有些泄露实现细节。
253-
254-
如果你仍然需要访问该 DOM,可以使用 `this.__v.__e`;其中 `.__v` 是组件关联的 VNode(经过混淆的属性名),`.__e` 则是该 VNode 关联的 DOM 节点。
255-
256-
### `preact/compat` 移除 `SuspenseList`
257-
258-
该功能的实现和服务端支持一直不够清晰和完整,因而我们决定移除它。
259-
260-
### 类型相关变更
261-
262-
#### `useRef` 现在需要初始值
263-
264-
与 React 19 中的更改类似,我们将 `useRef` 的类型签名改为需要提供初始值。提供初始值有助于类型推断并避免一些类型上的问题。
265-
266-
#### `JSX` 命名空间收缩
267-
268-
TypeScript 使用特殊的 `JSX` 命名空间来改变 JSX 的类型和解释方式。在 10 版本中,我们大幅扩展了该命名空间以包含多种有用类型,但其中许多更适合放到 `preact` 命名空间。
269-
270-
从 Preact 11 开始,`JSX` 命名空间将只包含 TypeScript 所需的基本类型(例如 `Element``IntrinsicElements` 等),其余类型将迁移到 `preact` 命名空间。这也有助于编辑器和 IDE 在自动导入提示时更好地解析类型。
271-
272-
```ts
273-
// Preact 10
274-
import { JSX } from 'preact';
275-
276-
type MyCustomButtonProps = JSX.ButtonHTMLAttributes & {
277-
/* ... */
278-
};
279-
280-
// Preact 11
281-
import { ButtonHTMLAttributes } from 'preact';
282-
283-
type MyCustomButtonProps = ButtonHTMLAttributes & {
284-
/* ... */
285-
};
286-
```

plugins/precompile-markdown/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ marked.use({
101101
code({ text, lang }) {
102102
const [code, source, runInRepl] = processRepl(text.trim());
103103

104-
Prism.languages[lang] == null
105-
? console.warn(`No Prism highlighter for language: ${lang}`)
106-
: (text = Prism.highlight(code, Prism.languages[lang], lang));
104+
if (Prism.languages[lang] == null) {
105+
throw new Error(
106+
`No Prism highlighter for language: ${lang}\n\ncode:\n${code}\n`
107+
);
108+
}
109+
110+
text = Prism.highlight(code, Prism.languages[lang], lang);
107111

108112
const runInReplLink = runInRepl
109113
? `<a class="repl-link" href="/repl?code=${encodeURIComponent(
@@ -238,9 +242,13 @@ function highlightCodeBlocks(data) {
238242

239243
const lang = child.getAttribute('class').replace('language-', '');
240244

241-
Prism.languages[lang] == null
242-
? console.warn(`No Prism highlighter for language: ${lang}`)
243-
: (child.innerHTML = Prism.highlight(code, Prism.languages[lang], lang));
245+
if (Prism.languages[lang] == null) {
246+
throw new Error(
247+
`No Prism highlighter for language: ${lang}\n\ncode:\n${code}\n`
248+
);
249+
}
250+
251+
child.innerHTML = Prism.highlight(code, Prism.languages[lang], lang);
244252

245253
block.insertAdjacentHTML(
246254
'beforebegin',

0 commit comments

Comments
 (0)