Skip to content

fix(react): guard against undefined $$typeof in check() - #17553

Open
Clickin wants to merge 1 commit into
withastro:mainfrom
Clickin:fix/react-check-undefined-typeof
Open

fix(react): guard against undefined $$typeof in check()#17553
Clickin wants to merge 1 commit into
withastro:mainfrom
Clickin:fix/react-check-undefined-typeof

Conversation

@Clickin

@Clickin Clickin commented Jul 30, 2026

Copy link
Copy Markdown

Changes

Adds a null guard in the check() function in @astrojs/react's server renderer to prevent TypeError when Component["$$typeof"] is undefined on non-React component objects.

Background

When @astrojs/react is used alongside other framework integrations (e.g. @astrojs/svelte), the check() function may receive non-React component objects. The current code calls .toString() on Component["$$typeof"] without checking if it exists:

if (typeof Component === "object") {
    return Component["$$typeof"].toString()... // TypeError when $$typeof is undefined
}

Fix

Extract $$typeof into a local variable and use != null short-circuit, returning false for components that lack the property:

if (typeof Component === "object") {
    const $$typeof = Component["$$typeof"];
    return $$typeof != null && $$typeof.toString().slice("Symbol(".length).startsWith("react");
}

Related issue

Closes #17552

@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 42cbca0

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.

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

@github-actions github-actions Bot added pkg: react Related to React (scope) pkg: integration Related to any renderer integration (scope) labels Jul 30, 2026
The check() function assumes Component['48357typeof'] is always defined
when typeof Component === 'object', but non-React component objects
(e.g. Svelte components imported via barrel) may not have 48357typeof.
Calling .toString() on undefined throws TypeError.

Add a null guard so the check returns false for non-React components
instead of crashing.
@Clickin
Clickin force-pushed the fix/react-check-undefined-typeof branch from 1e7a9e2 to 42cbca0 Compare July 30, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope) pkg: react Related to React (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

react: check() crashes on non-React component objects - 48357typeof undefined

1 participant