Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace use-subscription with use-sync-external-store #36733

Merged
merged 6 commits into from May 8, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 0 additions & 21 deletions packages/next/compiled/use-subscription/LICENSE

This file was deleted.

25 changes: 0 additions & 25 deletions packages/next/compiled/use-subscription/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/compiled/use-subscription/package.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/next/package.json
Expand Up @@ -72,7 +72,8 @@
"@next/env": "12.1.7-canary.3",
"caniuse-lite": "^1.0.30001332",
"postcss": "8.4.5",
"styled-jsx": "5.0.2"
"styled-jsx": "5.0.2",
"use-sync-external-store": "1.1.0"
},
"peerDependencies": {
"fibers": ">= 3.1.0",
Expand Down Expand Up @@ -260,7 +261,6 @@
"tty-browserify": "0.0.1",
"ua-parser-js": "0.7.28",
"unistore": "3.4.1",
"use-subscription": "1.5.1",
"util": "0.12.4",
"uuid": "8.3.2",
"vm-browserify": "1.1.2",
Expand Down
11 changes: 9 additions & 2 deletions packages/next/shared/lib/loadable.js
Expand Up @@ -22,7 +22,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
// Modified to be compatible with webpack 4 / Next.js

import React from 'react'
import { useSubscription } from 'next/dist/compiled/use-subscription'
import { useSyncExternalStore } from 'use-sync-external-store/shim'

import { LoadableContext } from './loadable-context'

const ALL_INITIALIZERS = []
Expand Down Expand Up @@ -75,6 +76,7 @@ function createLoadableComponent(loadFn, options) {
opts.lazy = React.lazy(opts.loader)
}

/** @type LoadableSubscription */
let subscription = null
function init() {
if (!subscription) {
Expand Down Expand Up @@ -116,7 +118,12 @@ function createLoadableComponent(loadFn, options) {
init()

const context = React.useContext(LoadableContext)
const state = useSubscription(subscription)
const state = useSyncExternalStore(
subscription.subscribe,
subscription.getCurrentValue,
subscription.getCurrentValue
)

React.useImperativeHandle(
ref,
() => ({
Expand Down
19 changes: 0 additions & 19 deletions packages/next/taskfile.js
Expand Up @@ -306,24 +306,6 @@ export async function ncc_react_refresh_utils(task, opts) {
}
}

// eslint-disable-next-line camelcase
export async function ncc_use_subscription(task, opts) {
await task
.source(
opts.src || relative(__dirname, require.resolve('use-subscription'))
)
.ncc({
packageName: 'use-subscription',
externals: {
...externals,
react: 'react',
'react-dom': 'react-dom',
},
target: 'es5',
})
.target('compiled/use-subscription')
}

// eslint-disable-next-line camelcase
externals['chalk'] = 'next/dist/compiled/chalk'
export async function ncc_chalk(task, opts) {
Expand Down Expand Up @@ -1652,7 +1634,6 @@ export async function ncc(task, opts) {
'ncc_node_html_parser',
'ncc_watchpack',
'ncc_chalk',
'ncc_use_subscription',
'ncc_napirs_triples',
'ncc_etag',
'ncc_p_limit',
Expand Down
10 changes: 4 additions & 6 deletions yarn.lock
Expand Up @@ -21248,12 +21248,10 @@ url@^0.11.0:
punycode "1.3.2"
querystring "0.2.0"

use-subscription@1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/use-subscription/-/use-subscription-1.5.1.tgz#73501107f02fad84c6dd57965beb0b75c68c42d1"
integrity sha512-Xv2a1P/yReAjAbhylMfFplFKj9GssgTwN7RlcTxBujFQcloStWNDQdc4g4NRWH9xS4i/FDk04vQBptAXoF3VcA==
dependencies:
object-assign "^4.1.1"
use-sync-external-store@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.1.0.tgz#3343c3fe7f7e404db70f8c687adf5c1652d34e82"
integrity sha512-SEnieB2FPKEVne66NpXPd1Np4R1lTNKfjuy3XdIoPQKYBAFdzbzSZlSn1KJZUiihQLQC5Znot4SBz1EOTBwQAQ==

use@^3.1.0:
version "3.1.1"
Expand Down