Skip to content

fix(examples): guard missing mount target in preact simple example#10208

Merged
TkDodo merged 1 commit intoTanStack:mainfrom
grzdev:fix/examples-preact-mount-target-guard
Mar 2, 2026
Merged

fix(examples): guard missing mount target in preact simple example#10208
TkDodo merged 1 commit intoTanStack:mainfrom
grzdev:fix/examples-preact-mount-target-guard

Conversation

@grzdev
Copy link
Contributor

@grzdev grzdev commented Mar 2, 2026

🎯 Changes

What
Adds a safety guard for the Preact simple example mount target before calling render().

Why
The example previously passed the mount target directly:
document.getElementById('app')

If the DOM element is missing or renamed, the example can fail at runtime with an unclear error. Since examples are frequently copied, adding an explicit guard improves reliability and developer experience.

Changes

  • Adds a runtime check for the #app element
  • Throws a clear error when the mount target is missing
  • Passes the verified element into render()

Scope
Examples-only change. No package/runtime changes.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling in the example application to detect and report missing initialization elements, ensuring clearer error messages during startup.

@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

⚠️ No Changeset found

Latest commit: be1bdde

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f010bc5 and be1bdde.

📒 Files selected for processing (1)
  • examples/preact/simple/src/index.tsx

📝 Walkthrough

Walkthrough

The change adds explicit null-safety handling to the render call in the Preact example. Instead of passing possibly null element directly to render, the app element is now retrieved into a variable with a runtime check that throws if missing before rendering.

Changes

Cohort / File(s) Summary
Null-safety in render call
examples/preact/simple/src/index.tsx
Replaces inline document.getElementById('app') call in render with explicit variable retrieval and runtime validation that throws if the #app element is missing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

Poem

🐰 Hop hop, no more null!
The app element now checked with care,
Throws if missing from anywhere,
No crashes lurk in silent air,
Our render stands secure and fair! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a guard/safety check for the missing mount target in the Preact example.
Description check ✅ Passed The description follows the template structure with complete 'Changes' section and properly filled 'Checklist' and 'Release Impact' sections addressing all required elements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

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

@nx-cloud
Copy link

nx-cloud bot commented Mar 2, 2026

View your CI Pipeline Execution ↗ for commit be1bdde

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded <1s View ↗
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 29s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-02 08:18:32 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 2, 2026

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/TanStack/query/@tanstack/angular-query-experimental@10208

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/eslint-plugin-query@10208

@tanstack/preact-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/preact-query@10208

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/preact-query-devtools@10208

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/preact-query-persist-client@10208

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-async-storage-persister@10208

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-broadcast-client-experimental@10208

@tanstack/query-core

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-core@10208

@tanstack/query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-devtools@10208

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-persist-client-core@10208

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-sync-storage-persister@10208

@tanstack/react-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query@10208

@tanstack/react-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query-devtools@10208

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query-next-experimental@10208

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query-persist-client@10208

@tanstack/solid-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/solid-query@10208

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/solid-query-devtools@10208

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/solid-query-persist-client@10208

@tanstack/svelte-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/svelte-query@10208

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/svelte-query-devtools@10208

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/svelte-query-persist-client@10208

@tanstack/vue-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/vue-query@10208

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/vue-query-devtools@10208

commit: d1157c1

@TkDodo TkDodo merged commit 234c16e into TanStack:main Mar 2, 2026
6 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.

2 participants