Skip to content

Uncomment bad examples, cross-link guides#28323

Merged
elithrar merged 2 commits intoproductionfrom
opencode/issue28322-20260213144814
Feb 14, 2026
Merged

Uncomment bad examples, cross-link guides#28323
elithrar merged 2 commits intoproductionfrom
opencode/issue28322-20260213144814

Conversation

@ask-bonk
Copy link
Contributor

@ask-bonk ask-bonk bot commented Feb 13, 2026

Here is a summary of all changes:

Workers Best Practices (workers-best-practices.mdx)

Uncommented 9 bad code examples — each now shows real, runnable TypeScript instead of commented-out code. The bad examples use a const badHandler = { ... } satisfies ExportedHandler<Env> pattern so they are valid TypeScript while clearly labeled with // 🔴 Bad:

Section What changed
Stream request/response bodies Buffering example is now a real badHandler
Use waitUntil Destructured ctx example is now a real badHandler
Use bindings, not REST APIs REST API call is now a real badHandler
Use Hyperdrive Direct DB connection is now a real badHandler
Do not store request-scoped state in global scope Global let currentUser + badHandler shown as real code
Always await your Promises Floating fetch() call is now uncommented
Use Web Crypto Math.random() token is now assigned to badToken
Timing-safe comparison Insecure === comparison is now a real verifyTokenInsecure function
Do not use passThroughOnException passThroughOnException() call is now a real badHandler
Observability (structured logging) Unstructured console.log is now a real badHandler

Cross-links added

  • Rules of Durable Objects: new "Related resources" section linking to Workers Best Practices and Rules of Workflows
  • Rules of Workflows: new "Related resources" section linking to Workers Best Practices and Rules of Durable Objects
  • Workers Best Practices: already had cross-links to both (no change needed)

Validation

npm run check passes with 0 errors and 0 warnings.

Closes #28322

github run

…k related guides

Show bad code examples as real code (matching DO/Workflows style) instead
of commented-out blocks. Each bad example uses a const handler pattern so
it remains valid TypeScript while clearly labeled with 🔴 Bad.

Also adds Related resources cross-links between Workers Best Practices,
Rules of Durable Objects, and Rules of Workflows so users can discover
all three guides.
@github-actions github-actions bot added product:workers Related to Workers product product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:workflows Workflows: https://developers.cloudflare.com/workflows/ size/l labels Feb 13, 2026
@github-actions
Copy link
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/durable-objects/ @elithrar, @vy-ton, @joshthoward, @oxyjun, @lambrospetrou, @mikenomitch, @cloudflare/pcx-technical-writing
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/pcx-technical-writing, @cloudflare/wrangler, @mattietk, @cloudflare/dev-plat-leads
/src/content/docs/workflows/ @elithrar, @celso, @mia303, @jonesphillip, @cloudflare/pcx-technical-writing

@ask-bonk
Copy link
Contributor Author

ask-bonk bot commented Feb 13, 2026

Done. Here is a summary of what was fixed and reviewed:

Changes made

Fixed indentation across all 30 code examples in rules-of-durable-objects.mdx. The previous commit had introduced two systematic indentation issues:

  1. Stripped indentation — Several code blocks had their tab indentation completely removed, putting class members and their bodies at column 0 (e.g., the SeatBooking.bookSeat() method, the bad ChatRoom.sendMessage() example, type Message declarations, and the Vitest describe block).

  2. Spaces instead of tabs — Many other blocks had tabs replaced with spaces (4-space or 5-space padding), creating inconsistent indentation within the same code block (e.g., the export default handlers, ChatRoom constructor/methods, alarm handlers, WebSocket handlers, clearStorage(), etc.).

Both issues are now fixed — all code examples use consistent tab indentation matching the repository's style.

TypeScript review

All 30 code examples were reviewed for correctness. No TypeScript issues found. All examples use correct:

  • DurableObject imports and class signatures
  • SQL API (exec, one(), toArray()) with proper generics
  • KV storage API (get, put, delete)
  • WebSocket Hibernation API (acceptWebSocket, getWebSockets, serializeAttachment, webSocketMessage/Close/Error handlers)
  • Alarm API (setAlarm, deleteAlarm, alarm() with AlarmInvocationInfo)
  • Namespace methods (idFromName, getByName, newUniqueId, get with locationHint)
  • blockConcurrencyWhile() patterns
  • Module worker export default patterns

Validation

npm run check passes with 0 errors, 0 warnings.

github run

@elithrar elithrar enabled auto-merge (squash) February 13, 2026 15:19
@elithrar
Copy link
Collaborator

I've reviewed - this is mostly style. Code format changes did not break the examples.

@elithrar elithrar merged commit a2ca278 into production Feb 14, 2026
9 checks passed
@elithrar elithrar deleted the opencode/issue28322-20260213144814 branch February 14, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:workers Related to Workers product product:workflows Workflows: https://developers.cloudflare.com/workflows/ size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve best practices good vs bad code examples

10 participants