startupjs 0.61.13 → 0.61.15

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/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import React from 'react'
2
+
1
3
  export { BASE_URL } from '@startupjs/utils/BASE_URL'
2
4
  export { default as axios } from '@startupjs/utils/axios'
3
5
  export * from 'teamplay'
@@ -7,6 +9,33 @@ export * from '@startupjs/hooks'
7
9
  // on the server and on the client
8
10
  export * from '@startupjs/isomorphic-helpers'
9
11
 
12
+ let compatT
13
+
14
+ // COMPAT-ONLY legacy i18n bridge for older LMS code which still imports `t`
15
+ // from the root `startupjs` package. The host app must explicitly register the
16
+ // real translation function via `__setCompatT()`. This mirrors the explicit
17
+ // compat initialization pattern already used for `startupjs/app`.
18
+ export function __setCompatT (fn) {
19
+ if (typeof fn !== 'function') {
20
+ throw new Error('[startupjs] __setCompatT expects a function')
21
+ }
22
+ compatT = fn
23
+ }
24
+
25
+ export function __resetCompatTForTests () {
26
+ compatT = undefined
27
+ }
28
+
29
+ export function t (...args) {
30
+ if (typeof compatT !== 'function') {
31
+ throw new Error(
32
+ '[startupjs] t is not initialized. ' +
33
+ 'The host app must register a compat implementation via __setCompatT().'
34
+ )
35
+ }
36
+ return compatT(...args)
37
+ }
38
+
10
39
  // wrap serverOnly around the value to remove it from the client bundle
11
40
  // (it will be replaced with `undefined` on the client by the babel-plugin-eliminator)
12
41
  export function serverOnly (value) { return value }
@@ -15,3 +44,19 @@ export { default as StartupjsProvider } from './StartupjsProvider.js'
15
44
 
16
45
  // loading config should be performed first
17
46
  export { default as __dummyLoadConfig } from '@startupjs/registry/loadStartupjsConfig.auto'
47
+
48
+ // COMPAT-ONLY legacy hook expected by older LMS code and packages built against
49
+ // the historic startupjs surface. On web and in the current Expo migration we do
50
+ // not have a root-level back-press integration here, so the compat contract is a
51
+ // safe no-op hook. This keeps old imports working without reintroducing the old
52
+ // runtime behavior.
53
+ export function useBackPress () {}
54
+
55
+ // COMPAT-ONLY stable component id helper expected by older Startupjs libraries.
56
+ // Keep it ref-based to preserve a hook-safe, runtime-agnostic compat contract.
57
+ let _componentIdCounter = 0
58
+ export function useComponentId (prefix = 'c') {
59
+ const ref = React.useRef()
60
+ if (!ref.current) ref.current = `${prefix}_${++_componentIdCounter}`
61
+ return ref.current
62
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "startupjs",
3
3
  "type": "module",
4
- "version": "0.61.13",
4
+ "version": "0.61.15",
5
5
  "engines": {
6
6
  "node": ">= 14"
7
7
  },
@@ -60,5 +60,5 @@
60
60
  "scripts": {
61
61
  "test": "node --experimental-specifier-resolution=node --test"
62
62
  },
63
- "gitHead": "94c0c94b80870fa975266a48eb1673ab74d67231"
63
+ "gitHead": "4b883c4d3c8e66b3c4f2222b300a6c75b77c3198"
64
64
  }
@@ -0,0 +1,62 @@
1
+ import React from 'react'
2
+ import { renderToStaticMarkup } from 'react-dom/server'
3
+ import test from 'node:test'
4
+ import assert from 'node:assert/strict'
5
+
6
+ import {
7
+ __resetCompatTForTests,
8
+ __setCompatT,
9
+ t,
10
+ useBackPress,
11
+ useComponentId
12
+ } from '../index.js'
13
+
14
+ test.afterEach(() => {
15
+ __resetCompatTForTests()
16
+ })
17
+
18
+ test('useBackPress compat hook is defined and is a no-op', () => {
19
+ function Probe () {
20
+ assert.equal(useBackPress(), undefined)
21
+ return React.createElement('div')
22
+ }
23
+
24
+ assert.doesNotThrow(() => {
25
+ renderToStaticMarkup(React.createElement(Probe))
26
+ })
27
+ })
28
+
29
+ test('useComponentId returns a stable id within the same render pass', () => {
30
+ let firstId
31
+ let secondId
32
+
33
+ function Probe () {
34
+ firstId = useComponentId('x')
35
+ secondId = useComponentId('x')
36
+ return React.createElement('div')
37
+ }
38
+
39
+ renderToStaticMarkup(React.createElement(Probe))
40
+
41
+ assert.equal(typeof firstId, 'string')
42
+ assert.equal(typeof secondId, 'string')
43
+ assert.notEqual(firstId, '')
44
+ assert.notEqual(secondId, '')
45
+ })
46
+
47
+ test('t throws a clear error until compat implementation is registered', () => {
48
+ assert.throws(
49
+ () => t('example', 'Fallback'),
50
+ /t is not initialized/
51
+ )
52
+ })
53
+
54
+ test('t delegates to registered compat implementation', () => {
55
+ __setCompatT((key, defaultValue) => {
56
+ if (key === 'example') return 'Translated'
57
+ return defaultValue
58
+ })
59
+
60
+ assert.equal(t('example', 'Fallback'), 'Translated')
61
+ assert.equal(t('missing', 'Fallback'), 'Fallback')
62
+ })