UNPKG

@nimpl/getters

Version:

Implementation of server getters in React Server Components without switching to SSR in next.js

17 lines (16 loc) 976 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAppPathname = getAppPathname; const work_unit_async_storage_external_1 = require("next/dist/server/app-render/work-unit-async-storage.external"); const server_getter_in_client_component_error_1 = require("./server-getter-in-client-component-error"); function getAppPathname() { (0, server_getter_in_client_component_error_1.serverGetterInClientComponentError)("getAppPathname"); // eslint-disable-next-line @typescript-eslint/no-explicit-any const pageStore = work_unit_async_storage_external_1.workUnitAsyncStorage.getStore(); const tags = (Array.isArray(pageStore.implicitTags.tags) && pageStore.implicitTags.tags) || (Array.isArray(pageStore.implicitTags) && pageStore.implicitTags) || []; const pageTags = tags.filter((tag) => tag.startsWith("_N_T_/")); const pathnameTag = pageTags[pageTags.length - 1]; return pathnameTag.substring(5); }