one 2.22.0 → 2.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/fork/getPathFromState.cjs +2 -1
- package/dist/cjs/fork/getPathFromState.native.cjs +4 -1
- package/dist/cjs/fork/getPathFromState.native.js +4 -1
- package/dist/cjs/fork/getPathFromState.native.js.map +1 -1
- package/dist/cjs/platform/streams.cjs +17 -0
- package/dist/cjs/platform/streams.native.cjs +19 -0
- package/dist/cjs/platform/streams.native.js +21 -0
- package/dist/cjs/platform/streams.native.js.map +1 -0
- package/dist/cjs/routeTypes.cjs +17 -0
- package/dist/cjs/routeTypes.native.cjs +19 -0
- package/dist/cjs/routeTypes.native.js +21 -0
- package/dist/cjs/routeTypes.native.js.map +1 -0
- package/dist/cjs/router/router.cjs +1 -1
- package/dist/cjs/router/router.native.cjs +1 -1
- package/dist/cjs/router/router.native.js +1 -1
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.cjs +22 -6
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.native.cjs +100 -25
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.native.js +100 -25
- package/dist/cjs/vite/plugins/iosLinkSetPlugin.native.js.map +1 -1
- package/dist/cjs/vite/plugins/oneNativeMembers.cjs +288 -57
- package/dist/cjs/vite/plugins/oneNativeMembers.native.cjs +537 -169
- package/dist/cjs/vite/plugins/oneNativeMembers.native.js +537 -169
- package/dist/cjs/vite/plugins/oneNativeMembers.native.js.map +1 -1
- package/dist/esm/fork/getPathFromState.mjs +2 -1
- package/dist/esm/fork/getPathFromState.mjs.map +1 -1
- package/dist/esm/fork/getPathFromState.native.js +4 -1
- package/dist/esm/fork/getPathFromState.native.js.map +1 -1
- package/dist/esm/platform/streams.mjs +0 -0
- package/dist/esm/platform/streams.native.js +0 -0
- package/dist/esm/routeTypes.mjs +0 -0
- package/dist/esm/routeTypes.native.js +0 -0
- package/dist/esm/router/router.mjs +2 -2
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +2 -2
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/vite/plugins/iosLinkSetPlugin.mjs +22 -6
- package/dist/esm/vite/plugins/iosLinkSetPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/iosLinkSetPlugin.native.js +100 -25
- package/dist/esm/vite/plugins/iosLinkSetPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/oneNativeMembers.mjs +289 -58
- package/dist/esm/vite/plugins/oneNativeMembers.mjs.map +1 -1
- package/dist/esm/vite/plugins/oneNativeMembers.native.js +538 -170
- package/dist/esm/vite/plugins/oneNativeMembers.native.js.map +1 -1
- package/ios/OneNativeSlot.swift +17 -0
- package/package.json +13 -13
- package/src/Root.tsx +1 -1
- package/src/constants.ts +1 -1
- package/src/createApp.native.tsx +1 -1
- package/src/createApp.tsx +3 -2
- package/src/fork/getPathFromState.test.ts +20 -0
- package/src/fork/getPathFromState.ts +8 -2
- package/src/headless.tsx +1 -1
- package/src/interfaces/router.ts +3 -27
- package/src/platform/file-system/classes.native.ts +6 -5
- package/src/platform/file-system/classes.ts +6 -5
- package/src/platform/streams.ts +14 -0
- package/src/routeTypes.ts +83 -0
- package/src/router/FlagsContext.ts +1 -1
- package/src/router/Route.tsx +1 -1
- package/src/router/getRoutes.ts +1 -1
- package/src/router/linkToColdRoute.test.ts +61 -1
- package/src/router/matchers.ts +1 -1
- package/src/router/router.ts +3 -8
- package/src/router/useInitializeOneRouter.ts +1 -1
- package/src/router/useViteRoutes.tsx +1 -1
- package/src/router/warmState.ts +1 -1
- package/src/types.ts +1 -1
- package/src/useMatches.ts +1 -1
- package/src/vite/one-server-only.tsx +5 -2
- package/src/vite/plugins/iosLinkSetPlugin.ts +39 -6
- package/src/vite/plugins/oneNativeMembers.ts +417 -82
- package/src/vite/types.ts +12 -51
- package/types/Root.d.ts +1 -1
- package/types/config.d.ts +1 -2
- package/types/config.d.ts.map +1 -1
- package/types/constants.d.ts +1 -1
- package/types/createApp.d.ts +3 -2
- package/types/createApp.d.ts.map +1 -1
- package/types/daemon/server.d.ts +1 -1
- package/types/fork/getPathFromState.d.ts.map +1 -1
- package/types/headless.d.ts +1 -1
- package/types/interfaces/router.d.ts +3 -19
- package/types/interfaces/router.d.ts.map +1 -1
- package/types/platform/file-system/classes.d.ts +4 -3
- package/types/platform/file-system/classes.d.ts.map +1 -1
- package/types/platform/file-system/classes.native.d.ts +4 -3
- package/types/platform/file-system/classes.native.d.ts.map +1 -1
- package/types/platform/streams.d.ts +12 -0
- package/types/platform/streams.d.ts.map +1 -0
- package/types/routeTypes.d.ts +66 -0
- package/types/routeTypes.d.ts.map +1 -0
- package/types/router/FlagsContext.d.ts +1 -1
- package/types/router/Route.d.ts +1 -1
- package/types/router/getRoutes.d.ts +1 -1
- package/types/router/matchers.d.ts +1 -1
- package/types/router/router.d.ts +1 -1
- package/types/router/router.d.ts.map +1 -1
- package/types/router/useInitializeOneRouter.d.ts +1 -1
- package/types/router/useViteRoutes.d.ts +1 -1
- package/types/router/warmState.d.ts +1 -1
- package/types/types.d.ts +1 -1
- package/types/useMatches.d.ts +1 -1
- package/types/vite/one-server-only.d.ts +5 -3
- package/types/vite/one-server-only.d.ts.map +1 -1
- package/types/vite/plugins/oneNativeMembers.d.ts +1 -1
- package/types/vite/plugins/oneNativeMembers.d.ts.map +1 -1
- package/types/vite/types.d.ts +12 -49
- package/types/vite/types.d.ts.map +1 -1
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { createNavigationContainerRef } from '@react-navigation/core'
|
|
2
2
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
3
|
import type { One } from '../vite/types'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
handleNavigationContainerStateChange,
|
|
6
|
+
initialize,
|
|
7
|
+
push,
|
|
8
|
+
replace,
|
|
9
|
+
rootStateSnapshot,
|
|
10
|
+
routeInfoSnapshot,
|
|
11
|
+
routeNode,
|
|
12
|
+
} from './router'
|
|
5
13
|
|
|
6
14
|
afterEach(() => {
|
|
7
15
|
vi.unstubAllEnvs()
|
|
@@ -11,6 +19,58 @@ afterEach(() => {
|
|
|
11
19
|
})
|
|
12
20
|
|
|
13
21
|
describe('navigation to a cold route', () => {
|
|
22
|
+
it('reconciles encoded dynamic parameters before a native pop', async () => {
|
|
23
|
+
vi.stubEnv('TAMAGUI_TARGET', 'native')
|
|
24
|
+
vi.stubGlobal('__vxrnHeadless', true)
|
|
25
|
+
vi.stubGlobal(
|
|
26
|
+
'requestAnimationFrame',
|
|
27
|
+
vi.fn(() => 1)
|
|
28
|
+
)
|
|
29
|
+
const files = {
|
|
30
|
+
'./_layout.tsx': { default: () => null },
|
|
31
|
+
'./index.tsx': { default: () => null },
|
|
32
|
+
'./items/[key].tsx': { default: () => null },
|
|
33
|
+
}
|
|
34
|
+
const context = ((id: string) => files[id]) as One.RouteContext
|
|
35
|
+
context.keys = () => Object.keys(files)
|
|
36
|
+
context.resolve = (id) => id
|
|
37
|
+
context.id = 'encoded-route'
|
|
38
|
+
const initial = {
|
|
39
|
+
key: 'stack-1',
|
|
40
|
+
type: 'stack' as const,
|
|
41
|
+
index: 0,
|
|
42
|
+
stale: false as const,
|
|
43
|
+
routeNames: ['index', 'items/[key]'],
|
|
44
|
+
routes: [{ key: 'index-1', name: 'index' }],
|
|
45
|
+
}
|
|
46
|
+
const navigator = {
|
|
47
|
+
isReady: () => true,
|
|
48
|
+
getRootState: () => initial,
|
|
49
|
+
getCurrentRoute: () => initial.routes[0],
|
|
50
|
+
resetRoot: vi.fn(),
|
|
51
|
+
dispatch: vi.fn(),
|
|
52
|
+
addListener: () => () => {},
|
|
53
|
+
removeListener: () => {},
|
|
54
|
+
}
|
|
55
|
+
const ref = createNavigationContainerRef()
|
|
56
|
+
ref.current = navigator as any
|
|
57
|
+
initialize(context, ref as any, new URL('http://one.test/'))
|
|
58
|
+
|
|
59
|
+
await push('/items/agent%3Aexample')
|
|
60
|
+
const committed = {
|
|
61
|
+
...initial,
|
|
62
|
+
index: 1,
|
|
63
|
+
routes: [
|
|
64
|
+
...initial.routes,
|
|
65
|
+
{ key: 'item-1', name: 'items/[key]', params: { key: 'agent:example' } },
|
|
66
|
+
],
|
|
67
|
+
}
|
|
68
|
+
handleNavigationContainerStateChange(committed)
|
|
69
|
+
expect(rootStateSnapshot()).toEqual(committed)
|
|
70
|
+
handleNavigationContainerStateChange(initial)
|
|
71
|
+
expect(routeInfoSnapshot().pathname).toBe('/')
|
|
72
|
+
})
|
|
73
|
+
|
|
14
74
|
it.each([
|
|
15
75
|
['native', 'development', true, false, false],
|
|
16
76
|
['web', 'development', false, false, false],
|
package/src/router/matchers.ts
CHANGED
package/src/router/router.ts
CHANGED
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
RouteValidationError,
|
|
45
45
|
validateParams as runValidateParams,
|
|
46
46
|
} from '../validateParams'
|
|
47
|
-
import type { One } from '../
|
|
47
|
+
import type { One } from '../routeTypes'
|
|
48
48
|
import {
|
|
49
49
|
extractParamsFromState,
|
|
50
50
|
extractPathnameFromHref,
|
|
@@ -67,12 +67,7 @@ import {
|
|
|
67
67
|
shouldAttemptWarmRouteRestore,
|
|
68
68
|
trackRestoredLaunch,
|
|
69
69
|
} from './warmState'
|
|
70
|
-
import {
|
|
71
|
-
getSafeWindowPath,
|
|
72
|
-
getSafeWindowPathname,
|
|
73
|
-
normalizeRoutePathname,
|
|
74
|
-
stripTrailingSlash,
|
|
75
|
-
} from './path'
|
|
70
|
+
import { getSafeWindowPath, getSafeWindowPathname, normalizeRoutePathname } from './path'
|
|
76
71
|
import type { RouteNode } from './Route'
|
|
77
72
|
import { sortRoutes } from './sortRoutes'
|
|
78
73
|
import { getQualifiedRouteComponent } from './useScreens'
|
|
@@ -1514,7 +1509,7 @@ export async function linkTo(
|
|
|
1514
1509
|
|
|
1515
1510
|
// a bit hacky until can figure out a reliable way to tie it to the state
|
|
1516
1511
|
nextOptions = options ?? null
|
|
1517
|
-
pendingNavigationPathname =
|
|
1512
|
+
pendingNavigationPathname = getRouteInfo(state).pathname
|
|
1518
1513
|
pendingNavigationAction =
|
|
1519
1514
|
event === 'PUSH' || event === 'REPLACE' || event === 'NAVIGATE' ? event : undefined
|
|
1520
1515
|
// record the user-intended pathname so late-mounting navigators (e.g. an
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ParamListBase, useNavigationContainerRef } from '@react-navigation/core'
|
|
2
2
|
import { resetLoaderState } from '../useLoader'
|
|
3
|
-
import type { One } from '../
|
|
3
|
+
import type { One } from '../routeTypes'
|
|
4
4
|
import type { OneLinkingConfig } from '../link/getLinking'
|
|
5
5
|
import * as routerStore from './router'
|
|
6
6
|
import { initialize } from './router'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GlobbedRouteImports } from '../types'
|
|
2
|
-
import type { One } from '../
|
|
2
|
+
import type { One } from '../routeTypes'
|
|
3
3
|
import { hasWebHistory, isNative } from '../constants'
|
|
4
4
|
import { handleSkewError, isChunkLoadError } from '../utils/dynamicImport'
|
|
5
5
|
import { diagnoseRouteLoadFailure } from './diagnoseRouteLoadFailure'
|
package/src/router/warmState.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getPathDataFromState } from '../fork/getPathFromState'
|
|
|
4
4
|
import { getStateFromPath } from '../fork/getStateFromPath'
|
|
5
5
|
import type { OneRouter } from '../interfaces/router'
|
|
6
6
|
import { Storage } from '../platform/storage'
|
|
7
|
-
import type { One } from '../
|
|
7
|
+
import type { One } from '../routeTypes'
|
|
8
8
|
import type { OneLinkingOptions } from './getLinkingConfig'
|
|
9
9
|
import { extractParamsFromState, findAllRouteNodesFromState } from './findRouteNode'
|
|
10
10
|
import type { RouteNode } from './Route'
|
package/src/types.ts
CHANGED
package/src/useMatches.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { startTransition, useEffect, useReducer } from 'react'
|
|
2
2
|
import { reviveLoaderData } from './loaderJSX'
|
|
3
3
|
import { useServerContext } from './vite/one-server-only'
|
|
4
|
-
import type { One } from './
|
|
4
|
+
import type { One } from './routeTypes'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Re-export for convenience
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// and then later its imported through optimizeDeps, a seaprate instance, creating a separate requestAsyncLocalStore
|
|
8
8
|
|
|
9
9
|
import { SERVER_CONTEXT_KEY } from '../constants'
|
|
10
|
-
import type { One } from '
|
|
10
|
+
import type { One } from '../routeTypes'
|
|
11
11
|
|
|
12
12
|
// symbol key for storing context directly on the ALS id object (faster than WeakMap)
|
|
13
13
|
const _ctxKey = Symbol.for('__oneCtx')
|
|
@@ -20,7 +20,10 @@ export interface ALSId {
|
|
|
20
20
|
|
|
21
21
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
interface ALSInstance {
|
|
24
|
+
getStore(): ALSId | undefined
|
|
25
|
+
run<R>(store: ALSId, callback: () => R): R
|
|
26
|
+
}
|
|
24
27
|
|
|
25
28
|
const key = '__vxrnrequestAsyncLocalStore'
|
|
26
29
|
const read = () => globalThis[key] as ALSInstance | undefined
|
|
@@ -51,6 +51,7 @@ function analysisPlugin(): Plugin {
|
|
|
51
51
|
const rewriteMembers = nativeOneMembers(
|
|
52
52
|
join(oneDirectory(), 'dist/esm/one-shared.native.js')
|
|
53
53
|
)
|
|
54
|
+
const escapes: string[] = []
|
|
54
55
|
|
|
55
56
|
return {
|
|
56
57
|
name: 'one:ios-link-set',
|
|
@@ -60,9 +61,10 @@ function analysisPlugin(): Plugin {
|
|
|
60
61
|
const file = id.split('?')[0]
|
|
61
62
|
if (file.startsWith('\0') || file.startsWith('virtual:')) return
|
|
62
63
|
if (own.some((dir) => file.startsWith(dir + '/'))) return
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if (mightUseGroups(code, keySet, pattern))
|
|
65
|
+
analyzeModule(code, file, keySet, usage)
|
|
66
|
+
if (!/["'`]one["'`]/.test(code)) return
|
|
67
|
+
return rewriteMembers(code, file, (reason) => escapes.push(`${file}: ${reason}`))
|
|
66
68
|
},
|
|
67
69
|
},
|
|
68
70
|
generateBundle(_options, bundle) {
|
|
@@ -71,15 +73,46 @@ function analysisPlugin(): Plugin {
|
|
|
71
73
|
if (!groups.includes('web')) groups.push('web')
|
|
72
74
|
}
|
|
73
75
|
const frameworks = new Set<string>()
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (const match of output.code.matchAll(
|
|
76
|
+
const scan = (code: string) => {
|
|
77
|
+
for (const match of code.matchAll(
|
|
77
78
|
/["'`]([A-Za-z_][A-Za-z0-9_]*)_([a-f0-9]{16})["'`]/g
|
|
78
79
|
)) {
|
|
79
80
|
if (match[2] === sdk.generation && sdkModules.has(match[1]))
|
|
80
81
|
frameworks.add(match[1])
|
|
81
82
|
}
|
|
82
83
|
}
|
|
84
|
+
for (const output of Object.values(bundle))
|
|
85
|
+
if (output.type === 'chunk') scan(output.code)
|
|
86
|
+
// the One object spreads every namespace, so a framework also has to sit in a
|
|
87
|
+
// module the app reaches without it. that holds while every app read of One was
|
|
88
|
+
// rewritten to the module defining it and only one's entry imports the object.
|
|
89
|
+
const dist = own.map((dir) => join(dir, 'dist/esm'))
|
|
90
|
+
const oneObject = dist.flatMap((dir) =>
|
|
91
|
+
['one.native.js', 'one-shared.native.js'].map((name) => join(dir, name))
|
|
92
|
+
)
|
|
93
|
+
const entries = dist.map((dir) => join(dir, 'index.native.js'))
|
|
94
|
+
if (
|
|
95
|
+
!escapes.length &&
|
|
96
|
+
!oneObject.some((id) =>
|
|
97
|
+
this.getModuleInfo(id)?.importers.some(
|
|
98
|
+
(importer) => !oneObject.includes(importer) && !entries.includes(importer)
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
) {
|
|
102
|
+
const inBundle = new Set(frameworks)
|
|
103
|
+
frameworks.clear()
|
|
104
|
+
const seen = new Set(
|
|
105
|
+
[...this.getModuleIds()].filter((id) => this.getModuleInfo(id)?.isEntry)
|
|
106
|
+
)
|
|
107
|
+
for (const id of seen) {
|
|
108
|
+
const info = this.getModuleInfo(id)
|
|
109
|
+
if (!info) continue
|
|
110
|
+
if (info.code) scan(info.code)
|
|
111
|
+
for (const next of [...info.importedIds, ...info.dynamicallyImportedIds])
|
|
112
|
+
if (!oneObject.includes(next)) seen.add(next)
|
|
113
|
+
}
|
|
114
|
+
for (const name of frameworks) if (!inBundle.has(name)) frameworks.delete(name)
|
|
115
|
+
}
|
|
83
116
|
const sdkFrameworks = [...frameworks].sort()
|
|
84
117
|
const report = process.env[IOS_LINK_SET_REPORT_ENV]
|
|
85
118
|
if (report)
|