one
Version:
One is a new React Framework that makes Vite serve both native and web.
105 lines (99 loc) • 5.92 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var Root_exports = {};
__export(Root_exports, {
Root: () => Root
});
module.exports = __toCommonJS(Root_exports);
var import_native = require("@react-navigation/native"), import_color_scheme = require("@vxrn/color-scheme"), import_react = require("react"), import_constants = require("./constants"), import_NavigationContainer = require("./fork/NavigationContainer"), import_getURL = require("./getURL"), import_FlagsContext = require("./router/FlagsContext"), import_linkingConfig = require("./router/linkingConfig"), import_serverLocationContext = require("./router/serverLocationContext"), import_useInitializeOneRouter = require("./router/useInitializeOneRouter"), import_useViteRoutes = require("./router/useViteRoutes"), import_useServerHeadInsertion = require("./useServerHeadInsertion"), import_PreloadLinks = require("./views/PreloadLinks"), import_RootErrorBoundary = require("./views/RootErrorBoundary"), import_ScrollBehavior = require("./views/ScrollBehavior"), import_jsx_runtime = require("react/jsx-runtime");
const ServerAsyncLocalIDContext = (0, import_react.createContext)(null);
globalThis.__vxrnGetContextFromReactContext = () => (0, import_react.useContext)(ServerAsyncLocalIDContext);
function Root(props) {
const { path, routes, routeOptions, isClient, navigationContainerProps, onRenderId } = props, context = (0, import_useViteRoutes.useViteRoutes)(
routes,
props.routerRoot,
routeOptions,
globalThis.__vxrnVersion
), location = typeof window < "u" && window.location ? new URL(path || window.location.href || "/", window.location.href) : new URL(path || "/", (0, import_getURL.getURL)()), store = (0, import_useInitializeOneRouter.useInitializeOneRouter)(context, location), userScheme = (0, import_color_scheme.useUserScheme)(), Component = store.rootComponent;
if (!Component)
throw new Error("No root component found");
const id = (0, import_react.useId)();
onRenderId?.(id);
const value = process.env.VERCEL ? globalThis.__oneGlobalContextId : globalThis.__vxrnrequestAsyncLocalStore?.getStore() || null;
let contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ServerAsyncLocalIDContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_useServerHeadInsertion.ServerRenderID.Provider, { value: id, children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_NavigationContainer.NavigationContainer,
{
ref: store.navigationRef,
initialState: store.initialState,
linking: (0, import_linkingConfig.getLinking)(),
onUnhandledAction,
theme: userScheme.value === "dark" ? import_native.DarkTheme : import_native.DefaultTheme,
documentTitle: {
enabled: !1
},
...navigationContainerProps,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_serverLocationContext.ServerLocationContext.Provider, { value: location, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ScrollBehavior.ScrollBehavior, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_RootErrorBoundary.RootErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) })
] }) })
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_PreloadLinks.PreloadLinks, {}, "preload-links")
] }) });
if (props.flags && (contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_FlagsContext.FlagsContext.Provider, { value: props.flags, children: contents })), process.env.ONE_DISABLE_STRICT_MODE || (contents = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.StrictMode, { children: contents })), isClient) {
if (globalThis[import_constants.SERVER_CONTEXT_KEY]?.mode === "spa") {
const [show, setShow] = (0, import_react.useState)(!1);
return (0, import_react.useLayoutEffect)(() => {
setShow(!0);
}, []), show ? contents : null;
}
return contents;
}
return contents;
}
let onUnhandledAction;
process.env.NODE_ENV !== "production" ? onUnhandledAction = (action) => {
const payload = action.payload;
let message = `The action '${action.type}'${payload ? ` with payload ${JSON.stringify(action.payload)}` : ""} was not handled by any navigator.`;
switch (action.type) {
case "NAVIGATE":
case "PUSH":
case "REPLACE":
case "JUMP_TO":
payload?.name ? message += `
Do you have a route named '${payload.name}'?` : message += `
You need to pass the name of the screen to navigate to. This may be a bug.`;
break;
case "GO_BACK":
case "POP":
case "POP_TO_TOP":
message += `
Is there any screen to go back to?`;
break;
case "OPEN_DRAWER":
case "CLOSE_DRAWER":
case "TOGGLE_DRAWER":
message += `
Is your screen inside a Drawer navigator?`;
break;
}
if (message += `
This is a development-only warning and won't be shown in production.`, process.env.NODE_ENV === "test")
throw new Error(message);
console.error(message);
} : onUnhandledAction = () => {
};
//# sourceMappingURL=Root.js.map