Skip to content

Commit

Permalink
Move createPortal to core (#3408)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Jan 13, 2022
1 parent e2eddf9 commit 436afec
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-melons-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact': minor
---

Move `createPortal` to the core package
4 changes: 2 additions & 2 deletions compat/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
Component,
createContext,
Fragment,
createRoot
createRoot,
createPortal
} from 'preact';
import {
useState,
Expand All @@ -26,7 +27,6 @@ import { forwardRef } from './forwardRef';
import { Children } from './Children';
import { Suspense, lazy } from './suspense';
import { SuspenseList } from './suspense-list';
import { createPortal } from './portals';
import {
hydrate,
render,
Expand Down
3 changes: 1 addition & 2 deletions compat/src/suspense.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, createElement, options, Fragment } from 'preact';
import { Component, createElement, options, Fragment, createPortal } from 'preact';
import { TYPE_ELEMENT, MODE_HYDRATE } from '../../src/constants';
import { getParentDom } from '../../src/tree';
import { createPortal } from './portals';

const oldCatchError = options._catchError;
/** @type {(error: any, internal: import('./internal').Internal) => void} */
Expand Down
2 changes: 1 addition & 1 deletion compat/src/portals.js → src/create-portal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement } from 'preact';
import { createElement } from './create-element';

/**
* Portal component
Expand Down
5 changes: 5 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ export interface ComponentClass<P = {}, S = {}> {
export interface ComponentConstructor<P = {}, S = {}>
extends ComponentClass<P, S> {}

export function createPortal(
vnode: VNode,
container: Element
): VNode<any>;

// Type alias for a component instance considered generally, whether stateless or stateful.
export type AnyComponent<P = {}, S = {}> =
| FunctionComponent<P>
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export { cloneElement } from './clone-element';
export { createContext } from './create-context';
export { toChildArray } from './diff/children';
export { default as options } from './options';
export { createPortal } from './create-portal';
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, {
import {
createElement,
render,
createPortal,
useState,
Component
} from 'preact/compat';
import { setupScratch, teardown } from '../../../test/_util/helpers';
import { getLog, clearLog } from '../../../test/_util/logCall';
} from 'preact';
import { useState } from 'preact/hooks';
import { setupRerender, act } from 'preact/test-utils';
import { setupScratch, teardown } from '../_util/helpers';
import { getLog, clearLog } from '../_util/logCall';

/* eslint-disable react/jsx-boolean-value, react/display-name, prefer-arrow-callback */
/** @jsx createElement */

describe('Portal', () => {
/** @type {HTMLDivElement} */
Expand Down

0 comments on commit 436afec

Please sign in to comment.