Skip to content

fix: externalize ably/react and JSX runtime imports, improve demo apps#56

Merged
ttypic merged 3 commits intomainfrom
update-demo-apps
Apr 15, 2026
Merged

fix: externalize ably/react and JSX runtime imports, improve demo apps#56
ttypic merged 3 commits intomainfrom
update-demo-apps

Conversation

@ttypic
Copy link
Copy Markdown
Contributor

@ttypic ttypic commented Apr 15, 2026

Accidentally broke demo apps (Turbopack stopped recognizing /react imports)

To fix this, externalized ably/react and JSX runtime imports.

Also fixed a small error in provider cleanup logic (unmount cleanup is now synchronous).

And updated demo apps to use createTransportHooks to avoid explicit types when using hooks.

@ttypic ttypic requested review from VeskeR and mschristensen April 15, 2026 11:22
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 15, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 92.58% 2086 / 2253
🔵 Statements 90.91% 2231 / 2454
🔵 Functions 93.18% 383 / 411
🔵 Branches 77.94% 947 / 1215
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/react/contexts/transport-provider.tsx 79.16% 83.33% 100% 85% 51, 69, 77-78
Generated in workflow #137 for commit bcea356 by the Vitest Coverage Report Action

@github-actions github-actions bot temporarily deployed to staging/pull/56/typedoc April 15, 2026 11:22 Inactive
ttypic added 3 commits April 15, 2026 15:34
The react bundle's external list only covered `ably` and `react`.
Sub-path imports (`ably/react`, `react/jsx-runtime`,
`react/jsx-dev-runtime`) were not externalized, so rolldown bundled
them as CJS and injected its interop shim into the ESM output. In
environments without `require` (Turbopack SSR, Node.js native ESM)
this threw "Calling `require` for X" at runtime. Adding all three to
`external` eliminates the shim entirely.
Switched the unmount cleanup from `useEffect` to `useLayoutEffect` so
the transport is closed and the ref cleared before the DOM is updated.
This ensures any in-progress operations are aborted before
`ChannelProvider` detaches the channel.

Also switched the transportRef from `| null` to `| undefined` to comply
with the project's `unicorn/no-null` rule.
Both demos now call `createTransportHooks<TEvent, TMessage>()` in their
`providers.tsx` and destructure `TransportProvider` and all hooks from
the returned object, rather than importing them directly from
`@ably/ai-transport/react`. This threads the codec generics through the
hook layer so hook calls don't need explicit type annotations at the
call site.
@ttypic ttypic merged commit 153932f into main Apr 15, 2026
12 checks passed
@ttypic ttypic deleted the update-demo-apps branch April 15, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants