diff --git a/.changeset/create-owner-internal.md b/.changeset/create-owner-internal.md new file mode 100644 index 0000000000..749904da04 --- /dev/null +++ b/.changeset/create-owner-internal.md @@ -0,0 +1,6 @@ +--- +"solid-js": patch +"@solidjs/web": patch +--- + +`createOwner` leaves solid-js's public types: it is typed only through `solid-js/internal`, like the boundary primitives behind `Errored`, `Loading` and `Reveal` (#3709). It stays a runtime export for the renderers. Solid 1.x had no `createOwner`, and application code that used it in an RC should host a scope with `createRoot()` (its `dispose` argument can be passed around as a plain function) and re-enter one with `runWithOwner()`. A detached `owner.dispose` keeps throwing, since it is a method and not part of the public API (#4444). diff --git a/packages/solid/src/index.ts b/packages/solid/src/index.ts index 1e8ecc46dd..90fa1a74b2 100644 --- a/packages/solid/src/index.ts +++ b/packages/solid/src/index.ts @@ -3,7 +3,6 @@ export { $TRACK, action, affects, - createOwner, createReaction, createTrackedEffect, deep, @@ -41,6 +40,12 @@ export { } from "@solidjs/signals"; /** @internal — the key a root owner carries `render`'s `onError` under, for the web runtime. */ export { ROOT_ERROR_HOOK } from "@solidjs/signals"; +// `createOwner`: a bare owner, for the runtimes' own scopes (`NoHydration`, +// `Portal`, a frame's fill). Exported at runtime (typed for renderers through +// `solid-js/internal`), `@internal` because application code hosts a scope +// with `createRoot()` and re-enters one with `runWithOwner()`, as in 1.x. +/** @internal */ +export { createOwner } from "@solidjs/signals"; export { from } from "./from.js"; export type { diff --git a/packages/solid/src/internal.ts b/packages/solid/src/internal.ts index 9a14d48a5f..f85d3702ca 100644 --- a/packages/solid/src/internal.ts +++ b/packages/solid/src/internal.ts @@ -25,7 +25,8 @@ * The boundary primitives behind `Errored`, `Loading`, and `Reveal` are * read back the same way (real on both entries), for renderers that * build boundaries without the components, and so are `sharedConfig` - * (the hydration/SSR coordination object) and the `$DEVCOMP` brand. + * (the hydration/SSR coordination object), the `$DEVCOMP` brand and + * `createOwner` (a bare owner for a runtime's own scope). * * Not here: the container-trace materializer. It lives in its own entry, * `solid-js/internal/container-trace`, so the store engine it builds on can @@ -37,6 +38,7 @@ import type { Accessor, Component, DynamicOptions, + Owner, RevealOrder, ServerErrorHook, ServerErrorSite @@ -171,6 +173,19 @@ export const getProjectionTrace: ( export const shareAsyncIterable: (source: AsyncIterable) => AsyncIterable = core.shareAsyncIterable; +/** + * A fresh owner under the current one (or a detached root if there is none), + * for a runtime's own scope: `NoHydration`, `Portal`, a frame's fill. `id` + * seeds the hydration ids of the tree it owns; `transparent` lets that tree + * draw ids from the parent's counter. Its `dispose` is a method + * (`owner.dispose()`), not a detached function. Not application API: an app + * hosts a scope with `createRoot()` and re-enters one with `runWithOwner()`. + */ +export const createOwner: (options?: { + id?: string; + transparent?: boolean; +}) => Owner & { dispose(self?: boolean): void } = core.createOwner; + /** The primitive behind ``: `fn()`, or `fallback(error, reset)` once something under it throws. */ export const createErrorBoundary: ( fn: () => T, diff --git a/packages/solid/src/server/index.ts b/packages/solid/src/server/index.ts index 786617b1b7..350005dea6 100644 --- a/packages/solid/src/server/index.ts +++ b/packages/solid/src/server/index.ts @@ -13,7 +13,6 @@ export { createDeferred, createOptimistic, createOptimisticStore, - createOwner, createProjection, createReaction, createRenderEffect, @@ -58,6 +57,12 @@ export { ROOT_ERROR_HOOK } from "./signals.js"; export type { ClientErrorContext, ClientErrorHook, ClientErrorsConfig } from "./signals.js"; +// `createOwner`: a bare owner, for the runtimes' own scopes (`NoHydration`, +// `Portal`, a frame's fill). Exported at runtime (typed for renderers through +// `solid-js/internal`), `@internal` because application code hosts a scope +// with `createRoot()` and re-enters one with `runWithOwner()`, as in 1.x. +/** @internal */ +export { createOwner } from "./signals.js"; // All type re-exports from signals export type { diff --git a/packages/web/frames/src/client.ts b/packages/web/frames/src/client.ts index 3719206b29..706231f1c5 100644 --- a/packages/web/frames/src/client.ts +++ b/packages/web/frames/src/client.ts @@ -19,6 +19,8 @@ import { OBSERVE, createMemo, + // @ts-expect-error `createOwner` is `@internal` in solid-js's declarations (typed in + // solid-js/internal); importing it from solid-js keeps it one binding in the bundle. createOwner, createRenderEffect, createSignal, diff --git a/packages/web/src/index.ts b/packages/web/src/index.ts index 06c4f93ebe..f3195c20dc 100644 --- a/packages/web/src/index.ts +++ b/packages/web/src/index.ts @@ -13,6 +13,8 @@ import { import { createComponent, createMemo, + // @ts-expect-error `createOwner` is `@internal` in solid-js's declarations (typed in + // solid-js/internal); importing it from solid-js keeps it one binding in the bundle. createOwner, createRoot, createSignal, diff --git a/packages/web/test/runtime/head.spec.js b/packages/web/test/runtime/head.spec.js index d012ba2cab..0f1ba27a10 100644 --- a/packages/web/test/runtime/head.spec.js +++ b/packages/web/test/runtime/head.spec.js @@ -12,7 +12,8 @@ * first registration and stays for the whole file. */ import * as r from "../../src/client.js"; -import { createRoot, createSignal, flush, createOwner, runWithOwner } from "solid-js"; +import { createRoot, createSignal, flush, runWithOwner } from "solid-js"; +import { createOwner } from "solid-js/internal"; import { peekNextChildId } from "@solidjs/signals"; // Registry applies on a microtask. diff --git a/packages/web/test/wait-asset.spec.tsx b/packages/web/test/wait-asset.spec.tsx index d33aa7b617..80003697cd 100644 --- a/packages/web/test/wait-asset.spec.tsx +++ b/packages/web/test/wait-asset.spec.tsx @@ -13,7 +13,8 @@ * allocated after the call). */ import { describe, expect, test } from "vitest"; -import { createRoot, createOwner, runWithOwner, getNextChildId, flush } from "solid-js"; +import { createRoot, runWithOwner, getNextChildId, flush } from "solid-js"; +import { createOwner } from "solid-js/internal"; import { effect } from "../src/render.js"; import { waitAsset } from "../src/client.js";