Skip to content

Commit

Permalink
chore: cleanup some internals and enable StrictMode
Browse files Browse the repository at this point in the history
canary1.1.434-1738836794800
  • Loading branch information
natew committed Feb 6, 2025
1 parent 6010571 commit 63c396e
Show file tree
Hide file tree
Showing 61 changed files with 170 additions and 279 deletions.
2 changes: 1 addition & 1 deletion apps/devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "devtools",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"type": "module",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions apps/onestack.dev/data/docs/helpers-utility-functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const postPageLink = href(`/post/hello-world`) // will type error if invalid Hre

<Status is="developing" />

For improving performance of client hydration on the web, you can pass data from the server to the client with `requestCache`, on native values will always be `undefined`. Data must be JSON-stringifyable and on native.
For improving performance of client hydration on the web, you can pass data from the server to the client. Data must be serializable to JSON.

Here's an example of a simple `useFetch` to show how it's useful:
Here's an example of a simple `useFetch`:

```tsx fileName=app/index.tsx
import { setServerData, getServerData } from 'one'
Expand Down
2 changes: 1 addition & 1 deletion apps/onestack.dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "site",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"sideEffects": false,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion examples/bare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-bare",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"type": "module",
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion examples/expo-blank/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-blank-app",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"main": "expo/AppEntry.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/one-basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-basic",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/one-recommended/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-recommended",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/one-tailwind/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-tailwind",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/one-tamagui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-tamagui",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/one-zero/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "one-zero",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"sideEffects": false,
"files": [],
Expand Down
2 changes: 1 addition & 1 deletion examples/testflight/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "example-testflight",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/better-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vxrn/better-auth",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"sideEffects": false,
"types": "./src/index.ts",
"main": "dist/cjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/color-scheme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vxrn/color-scheme",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"sideEffects": false,
"exports": {
"./package.json": "./package.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vxrn/compiler",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"type": "module",
"exports": {
"./package.json": "./package.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vxrn/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-vxrn",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"bin": "run.js",
"main": "dist/cjs",
"module": "dist/esm",
Expand Down
2 changes: 1 addition & 1 deletion packages/debug/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vxrn/debug",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"sideEffects": false,
"source": "src/index.ts",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/emitter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vxrn/emitter",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"sideEffects": false,
"source": "src/index.ts",
"types": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/lllink/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lllink",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"type": "module",
"module": "dist",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vxrn/mdx",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"type": "commonjs",
"exports": {
"./package.json": "./package.json",
Expand Down
2 changes: 1 addition & 1 deletion packages/one/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "one",
"version": "1.1.434",
"version": "1.1.434-1738836794800",
"license": "BSD-3-Clause",
"sideEffects": [
"setup.mjs",
Expand Down
85 changes: 41 additions & 44 deletions packages/one/src/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { useColorScheme } from '@vxrn/universal-color-scheme'
import {
createContext,
Suspense,
StrictMode,
useContext,
useEffect,
useId,
Expand Down Expand Up @@ -63,7 +63,6 @@ globalThis['__vxrnGetContextFromReactContext'] = () => useContext(ServerAsyncLoc
export function Root(props: RootProps) {
const { path, routes, routeOptions, isClient, navigationContainerProps, onRenderId } = props

// ⚠️ <StrictMode> breaks routing!
const context = useViteRoutes(routes, routeOptions, globalThis['__vxrnVersion'])
const location =
typeof window !== 'undefined' && window.location
Expand All @@ -87,49 +86,47 @@ export function Root(props: RootProps) {

const value = globalThis['__vxrnrequestAsyncLocalStore']?.getStore() || null

console.log('wtf', value)

const contents = (
// <StrictMode>
<ServerAsyncLocalIDContext.Provider value={value}>
<ServerRenderID.Provider value={id}>
<RootErrorBoundary>
{/* for some reason warning if no key here */}
<UpstreamNavigationContainer
ref={store.navigationRef}
initialState={store.initialState}
linking={store.linking}
onUnhandledAction={onUnhandledAction}
theme={colorScheme === 'dark' ? DarkTheme : DefaultTheme}
documentTitle={{
enabled: false,
}}
{...navigationContainerProps}
>
<ServerLocationContext.Provider value={location}>
{/* <GestureHandlerRootView> */}
{/*
* Due to static rendering we need to wrap these top level views in second wrapper
* View's like <GestureHandlerRootView /> generate a <div> so if the parent wrapper
* is a HTML document, we need to ensure its inside the <body>
*/}
<>
{/* default scroll restoration to on, but users can configure it by importing and using themselves */}
<ScrollBehavior />

<Component />

{/* Users can override this by adding another StatusBar element anywhere higher in the component tree. */}
</>
{/* {!hasViewControllerBasedStatusBarAppearance && <StatusBar style="auto" />} */}
{/* </GestureHandlerRootView> */}
</ServerLocationContext.Provider>
</UpstreamNavigationContainer>
<PreloadLinks key="preload-links" />
</RootErrorBoundary>
</ServerRenderID.Provider>
</ServerAsyncLocalIDContext.Provider>
// </StrictMode>
<StrictMode>
<ServerAsyncLocalIDContext.Provider value={value}>
<ServerRenderID.Provider value={id}>
<RootErrorBoundary>
{/* for some reason warning if no key here */}
<UpstreamNavigationContainer
ref={store.navigationRef}
initialState={store.initialState}
linking={store.linking}
onUnhandledAction={onUnhandledAction}
theme={colorScheme === 'dark' ? DarkTheme : DefaultTheme}
documentTitle={{
enabled: false,
}}
{...navigationContainerProps}
>
<ServerLocationContext.Provider value={location}>
{/* <GestureHandlerRootView> */}
{/*
* Due to static rendering we need to wrap these top level views in second wrapper
* View's like <GestureHandlerRootView /> generate a <div> so if the parent wrapper
* is a HTML document, we need to ensure its inside the <body>
*/}
<>
{/* default scroll restoration to on, but users can configure it by importing and using themselves */}
<ScrollBehavior />

<Component />

{/* Users can override this by adding another StatusBar element anywhere higher in the component tree. */}
</>
{/* {!hasViewControllerBasedStatusBarAppearance && <StatusBar style="auto" />} */}
{/* </GestureHandlerRootView> */}
</ServerLocationContext.Provider>
</UpstreamNavigationContainer>
<PreloadLinks key="preload-links" />
</RootErrorBoundary>
</ServerRenderID.Provider>
</ServerAsyncLocalIDContext.Provider>
</StrictMode>
)

if (isClient) {
Expand Down
4 changes: 1 addition & 3 deletions packages/one/src/createApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import type { RenderAppProps } from './types'
import ReactDOMServer from 'react-dom/server.browser'
import { getServerHeadInsertions } from './useServerHeadInsertion'
import { ensureExists } from './utils/ensureExists'
import { getServerContext, setServerContext } from './vite/one-server-only'
import { SERVER_CONTEXT_POST_RENDER_STRING } from './vite/constants'
import { useId } from 'react'
import { getServerContext, setServerContext } from './vite/one-server-only'

export type CreateAppProps = { routes: Record<string, () => Promise<unknown>> }

Expand All @@ -34,7 +33,6 @@ export function createApp(options: CreateAppProps) {
let renderId: string | undefined

const App = () => {
console.warn('rendering App()', useId())
return (
<Root
onRenderId={(id) => {
Expand Down
2 changes: 0 additions & 2 deletions packages/one/src/layouts/withLayoutContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ export function withLayoutContext<
onlyMatching: true,
})

console.warn('RENDERING WITH LAYOUT')

// Prevent throwing an error when there are no screens.
if (!sorted.length) {
return null
Expand Down
47 changes: 26 additions & 21 deletions packages/one/src/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@ import {
} from '@react-navigation/native'
import * as Linking from 'expo-linking'
import { nanoid } from 'nanoid/non-secure'
import { act, Fragment, startTransition, useSyncExternalStore, type ComponentType } from 'react'
import { Fragment, startTransition, type ComponentType, useSyncExternalStore } from 'react'
import { Platform } from 'react-native'
import type { RouteNode } from './Route'
import { getLoaderPath, getPreloadPath } from '../utils/cleanUrl'
import type { State } from '../fork/getPathFromState'
import { getPathDataFromState } from '../fork/getPathFromState'
import { stripBaseUrl } from '../fork/getStateFromPath-mods'
import { getLinkingConfig, type OneLinkingOptions } from './getLinkingConfig'
import { getRoutes } from './getRoutes'
import type { OneRouter } from '../interfaces/router'
import { resolveHref } from '../link/href'
import { resolve } from '../link/path'
import { matchDynamicName } from './matchers'
import { sortRoutes } from './sortRoutes'
import { getQualifiedRouteComponent } from './useScreens'
import { assertIsReady } from '../utils/assertIsReady'
import { getLoaderPath, getPreloadPath } from '../utils/cleanUrl'
import { dynamicImport } from '../utils/dynamicImport'
import { removeSearch } from '../utils/removeSearch'
import { shouldLinkExternally } from '../utils/url'
import type { One } from '../vite/types'
import { getLinkingConfig, type OneLinkingOptions } from './getLinkingConfig'
import { getNormalizedStatePath, type UrlObject } from './getNormalizedStatePath'
import { getRoutes } from './getRoutes'
import { setLastAction } from './lastAction'
import { matchDynamicName } from './matchers'
import type { RouteNode } from './Route'
import { sortRoutes } from './sortRoutes'
import { getQualifiedRouteComponent } from './useScreens'

// Module-scoped variables
export let routeNode: RouteNode | null = null
Expand Down Expand Up @@ -144,16 +143,20 @@ function subscribeToNavigationChanges() {
}

if (shouldUpdateSubscribers) {
for (const subscriber of rootStateSubscribers) {
subscriber(state)
}
startTransition(() => {
for (const subscriber of rootStateSubscribers) {
subscriber(state)
}
})
}
})

updateSnapshot()
for (const subscriber of storeSubscribers) {
subscriber()
}
startTransition(() => {
updateSnapshot()
for (const subscriber of storeSubscribers) {
subscriber()
}
})
}

// Navigation functions
Expand Down Expand Up @@ -285,9 +288,11 @@ export function subscribeToLoadingState(subscriber: OneRouter.LoadingStateListen
}

export function setLoadingState(state: OneRouter.LoadingState) {
for (const listener of loadingStateSubscribers) {
listener(state)
}
startTransition(() => {
for (const listener of loadingStateSubscribers) {
listener(state)
}
})
}

// Snapshot function
Expand Down Expand Up @@ -505,7 +510,6 @@ export async function linkTo(href: string, event?: string, options?: OneRouter.L
preloadRoute(href)

const rootState = navigationRef.getRootState()
const action = getNavigateAction(state, rootState, event)

const hash = href.indexOf('#')
if (rootState.key && hash > 0) {
Expand All @@ -516,9 +520,10 @@ export async function linkTo(href: string, event?: string, options?: OneRouter.L
nextOptions = options ?? null

startTransition(() => {
const action = getNavigateAction(state, rootState, event)
const current = navigationRef.getCurrentRoute()

navigationRef.dispatch(action)

let warningTm
const interval = setInterval(() => {
const next = navigationRef.getCurrentRoute()
Expand Down
Loading

0 comments on commit 63c396e

Please sign in to comment.