slicejs-web-framework 4.0.1 → 4.0.2

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.
Files changed (71) hide show
  1. package/.opencode/opencode.json +14 -14
  2. package/LICENSE +21 -21
  3. package/README.md +97 -97
  4. package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
  5. package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +470 -470
  6. package/Slice/Components/Structural/Controller/Controller.js +1406 -1406
  7. package/Slice/Components/Structural/Controller/allowedValuesValidation.js +52 -52
  8. package/Slice/Components/Structural/Debugger/Debugger.html +72 -72
  9. package/Slice/Components/Structural/Debugger/Debugger.js +1505 -1505
  10. package/Slice/Components/Structural/EventManager/EventManager.js +651 -651
  11. package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +985 -985
  12. package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -296
  13. package/Slice/Components/Structural/Logger/Log.js +10 -10
  14. package/Slice/Components/Structural/Logger/LogViewer/LogViewer.js +662 -662
  15. package/Slice/Components/Structural/Logger/Logger.js +225 -225
  16. package/Slice/Components/Structural/Router/Router.js +810 -793
  17. package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
  18. package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +175 -162
  19. package/Slice/Slice.js +708 -685
  20. package/Slice/tests/build-bundled-component-without-category.test.js +103 -103
  21. package/Slice/tests/build-js-only-visual-components.test.js +144 -144
  22. package/Slice/tests/build-singleton.test.js +244 -244
  23. package/Slice/tests/bundle-v2-runtime-contract.test.js +747 -738
  24. package/Slice/tests/context-patch-use.test.js +95 -95
  25. package/Slice/tests/destroy-cascade.test.js +215 -215
  26. package/Slice/tests/event-emitters.test.js +79 -79
  27. package/Slice/tests/event-registry.test.js +141 -141
  28. package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -21
  29. package/Slice/tests/leak-orphans.test.js +131 -131
  30. package/Slice/tests/props-allowed-values-validation.test.js +119 -119
  31. package/Slice/tests/public-env-runtime-accessors.test.js +44 -44
  32. package/Slice/tests/public-env-typed-accessors.test.js +66 -66
  33. package/Slice/tests/router-loading-finally.test.js +68 -68
  34. package/api/framework/devDepsOptimizer.js +335 -335
  35. package/api/framework/express.js +3 -3
  36. package/api/framework/precompressedStatic.js +93 -93
  37. package/api/framework/publicEnvResolver.js +123 -123
  38. package/api/framework/securityMiddleware.js +197 -197
  39. package/api/framework/server.js +411 -411
  40. package/api/index.js +7 -7
  41. package/api/tests/dev-deps-optimizer.test.js +137 -137
  42. package/api/tests/dev-server-external.test.js +56 -56
  43. package/api/tests/precompressed-static.test.js +119 -119
  44. package/api/tests/public-env-resolver.test.js +193 -193
  45. package/package.json +49 -49
  46. package/sliceConfig.schema.json +122 -122
  47. package/src/App/index.html +69 -69
  48. package/src/App/index.js +20 -20
  49. package/src/App/style.css +11 -11
  50. package/src/Components/AppComponents/AboutSection/AboutSection.css +9 -9
  51. package/src/Components/AppComponents/AboutSection/AboutSection.html +8 -8
  52. package/src/Components/AppComponents/AboutSection/AboutSection.js +12 -12
  53. package/src/Components/AppComponents/AppShell/AppShell.css +10 -10
  54. package/src/Components/AppComponents/AppShell/AppShell.html +4 -4
  55. package/src/Components/AppComponents/AppShell/AppShell.js +36 -36
  56. package/src/Components/AppComponents/HomeSection/HomeSection.css +20 -20
  57. package/src/Components/AppComponents/HomeSection/HomeSection.html +10 -10
  58. package/src/Components/AppComponents/HomeSection/HomeSection.js +19 -19
  59. package/src/Components/components.js +8 -8
  60. package/src/public/Styles/sliceStyles.css +34 -34
  61. package/src/public/Themes/Dark.css +42 -42
  62. package/src/public/Themes/Light.css +31 -31
  63. package/src/public/Themes/Slice.css +47 -47
  64. package/src/public/manifest.json +15 -15
  65. package/src/public/robots.txt +4 -4
  66. package/src/public/sitemap.xml +8 -8
  67. package/src/routes.js +9 -9
  68. package/src/sliceConfig.json +72 -72
  69. package/tests/router-build-failure.test.js +125 -0
  70. package/tests/router-emit-ordering.test.js +63 -63
  71. package/types/index.d.ts +219 -219
@@ -0,0 +1,125 @@
1
+ // Regression test: handleRoute() must not append a failed build to the DOM.
2
+ //
3
+ // slice.build() returns null on any unrecoverable path (component not
4
+ // registered, a resource fetch failed or was aborted mid-flight, init() threw).
5
+ // Passing that null straight to appendChild() raised
6
+ // TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'
7
+ // which surfaced far from the real cause and made the failure look like a DOM
8
+ // bug. handleRoute() now reports the build failure and leaves the current view
9
+ // in place.
10
+ //
11
+ // Router has no imports and no module-level DOM access, so its prototype can be
12
+ // exercised directly against stubs (same approach as router-emit-ordering).
13
+ //
14
+ // Run: node --test tests/router-build-failure.test.js
15
+
16
+ import { test, describe, before, beforeEach } from 'node:test';
17
+ import assert from 'node:assert/strict';
18
+
19
+ describe('Router.handleRoute — failed component build', () => {
20
+ let Router;
21
+ let appended;
22
+ let loggedErrors;
23
+ let appElement;
24
+
25
+ before(async () => {
26
+ globalThis.window = globalThis.window || { location: { pathname: '/' } };
27
+ globalThis.slice = globalThis.slice || {};
28
+ ({ default: Router } = await import('../Slice/Components/Structural/Router/Router.js'));
29
+ });
30
+
31
+ beforeEach(() => {
32
+ appended = [];
33
+ loggedErrors = [];
34
+ appElement = {
35
+ innerHTML: 'previous view',
36
+ appendChild(node) {
37
+ // Mirror the real DOM contract: appending a non-Node is a TypeError.
38
+ if (!node || typeof node !== 'object') {
39
+ throw new TypeError(
40
+ "Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'."
41
+ );
42
+ }
43
+ appended.push(node);
44
+ },
45
+ };
46
+
47
+ globalThis.document = { querySelector: (sel) => (sel === '#app' ? appElement : null) };
48
+ globalThis.slice = {
49
+ logger: { logError: (...args) => loggedErrors.push(args) },
50
+ controller: { getComponent: () => null },
51
+ router: {},
52
+ loading: null,
53
+ build: async () => null, // the failure under test
54
+ };
55
+ });
56
+
57
+ const makeRouter = () => {
58
+ const r = Object.create(Router.prototype);
59
+ r.renderRoutesInComponent = async () => {};
60
+ r.invalidateCache = () => {};
61
+ return r;
62
+ };
63
+
64
+ test('does not throw when slice.build() returns null', async () => {
65
+ const r = makeRouter();
66
+ await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
67
+ assert.equal(appended.length, 0, 'nothing should be appended');
68
+ });
69
+
70
+ test('logs the build failure naming the route and component', async () => {
71
+ const r = makeRouter();
72
+ await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
73
+
74
+ assert.equal(loggedErrors.length, 1, 'exactly one error should be reported');
75
+ const [scope, message] = loggedErrors[0];
76
+ assert.equal(scope, 'Router');
77
+ assert.match(message, /\/broken/);
78
+ assert.match(message, /Broken/);
79
+ });
80
+
81
+ test('leaves the current view untouched instead of blanking it', async () => {
82
+ const r = makeRouter();
83
+ await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
84
+ assert.equal(appElement.innerHTML, 'previous view');
85
+ });
86
+
87
+ test('does not mark the failed route as active', async () => {
88
+ const r = makeRouter();
89
+ await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
90
+ assert.equal(slice.router.activeRoute, undefined);
91
+ });
92
+
93
+ test('still stops the loading indicator', async () => {
94
+ const stops = [];
95
+ slice.loading = { start() {}, stop() { stops.push(1); } };
96
+
97
+ const r = makeRouter();
98
+ await r.handleRoute({ path: '/broken', component: 'Broken' }, {});
99
+ assert.equal(stops.length, 1, 'loading.stop() must run even on the failure path');
100
+ });
101
+
102
+ test('a successful build still renders and activates the route', async () => {
103
+ const component = { tagName: 'DIV' };
104
+ slice.build = async () => component;
105
+
106
+ const r = makeRouter();
107
+ const route = { path: '/ok', component: 'Ok' };
108
+ await r.handleRoute(route, {});
109
+
110
+ assert.deepEqual(appended, [component]);
111
+ assert.equal(appElement.innerHTML, '');
112
+ assert.equal(slice.router.activeRoute, route);
113
+ assert.equal(loggedErrors.length, 0);
114
+ });
115
+
116
+ test('reports instead of throwing when #app is missing', async () => {
117
+ globalThis.document = { querySelector: () => null };
118
+
119
+ const r = makeRouter();
120
+ await r.handleRoute({ path: '/ok', component: 'Ok' }, {});
121
+
122
+ assert.equal(loggedErrors.length, 1);
123
+ assert.match(loggedErrors[0][1], /#app/);
124
+ });
125
+ });
@@ -1,63 +1,63 @@
1
- // Regression test for GOTCHAS §3: router:change must not be observable before
2
- // slice.router.activeRoute is updated.
3
- //
4
- // Router is a plain class with no module-level DOM/global access and no imports,
5
- // so onRouteChange() can be exercised directly on a stubbed instance. The fix
6
- // makes onRouteChange() resolve only AFTER the debounced handleRoute() runs
7
- // (which is where activeRoute is set), so a caller that awaits it — like
8
- // _performNavigation — emits router:change with activeRoute already current.
9
- //
10
- // Run: node --test tests/router-emit-ordering.test.js
11
-
12
- import { test, describe, before } from 'node:test';
13
- import assert from 'node:assert/strict';
14
-
15
- describe('Router.onRouteChange (§3 emit-after-activeRoute)', () => {
16
- let Router;
17
-
18
- before(async () => {
19
- globalThis.window = globalThis.window || { location: { pathname: '/' } };
20
- globalThis.slice = globalThis.slice || { logger: { error() {} }, router: {} };
21
- ({ default: Router } = await import('../Slice/Components/Structural/Router/Router.js'));
22
- });
23
-
24
- const makeRouter = (handleRoute) => {
25
- const r = Object.create(Router.prototype);
26
- r.renderRoutesComponentsInPage = async () => false; // not the MultiRoute container path
27
- r.matchRoute = () => ({ route: { component: 'X' }, params: {} });
28
- r.handleRoute = handleRoute;
29
- return r;
30
- };
31
-
32
- test('awaiting onRouteChange() waits until handleRoute() has finished', async () => {
33
- const order = [];
34
- const r = makeRouter(async () => {
35
- await new Promise((res) => setTimeout(res, 5)); // simulate async render
36
- order.push('handleRoute-done'); // activeRoute is assigned here in the real code
37
- });
38
-
39
- await r.onRouteChange();
40
- order.push('after-await');
41
-
42
- // With the fix, handleRoute completes BEFORE the await returns. (Before the
43
- // fix the awaited promise resolved the instant the timer was scheduled, so
44
- // 'after-await' would land first — i.e. emit-before-activeRoute.)
45
- assert.deepEqual(order, ['handleRoute-done', 'after-await']);
46
- });
47
-
48
- test('a superseded (debounced) call still resolves — no hang', async () => {
49
- let handled = 0;
50
- const r = makeRouter(async () => { handled++; });
51
-
52
- const p1 = r.onRouteChange(); // schedules timer T1
53
- const p2 = r.onRouteChange(); // clears T1, resolves p1, schedules T2
54
-
55
- await Promise.race([
56
- Promise.all([p1, p2]),
57
- new Promise((_, rej) => setTimeout(() => rej(new Error('onRouteChange hung')), 1000)),
58
- ]);
59
-
60
- // Only the surviving timer runs its work.
61
- assert.equal(handled, 1);
62
- });
63
- });
1
+ // Regression test for GOTCHAS §3: router:change must not be observable before
2
+ // slice.router.activeRoute is updated.
3
+ //
4
+ // Router is a plain class with no module-level DOM/global access and no imports,
5
+ // so onRouteChange() can be exercised directly on a stubbed instance. The fix
6
+ // makes onRouteChange() resolve only AFTER the debounced handleRoute() runs
7
+ // (which is where activeRoute is set), so a caller that awaits it — like
8
+ // _performNavigation — emits router:change with activeRoute already current.
9
+ //
10
+ // Run: node --test tests/router-emit-ordering.test.js
11
+
12
+ import { test, describe, before } from 'node:test';
13
+ import assert from 'node:assert/strict';
14
+
15
+ describe('Router.onRouteChange (§3 emit-after-activeRoute)', () => {
16
+ let Router;
17
+
18
+ before(async () => {
19
+ globalThis.window = globalThis.window || { location: { pathname: '/' } };
20
+ globalThis.slice = globalThis.slice || { logger: { error() {} }, router: {} };
21
+ ({ default: Router } = await import('../Slice/Components/Structural/Router/Router.js'));
22
+ });
23
+
24
+ const makeRouter = (handleRoute) => {
25
+ const r = Object.create(Router.prototype);
26
+ r.renderRoutesComponentsInPage = async () => false; // not the MultiRoute container path
27
+ r.matchRoute = () => ({ route: { component: 'X' }, params: {} });
28
+ r.handleRoute = handleRoute;
29
+ return r;
30
+ };
31
+
32
+ test('awaiting onRouteChange() waits until handleRoute() has finished', async () => {
33
+ const order = [];
34
+ const r = makeRouter(async () => {
35
+ await new Promise((res) => setTimeout(res, 5)); // simulate async render
36
+ order.push('handleRoute-done'); // activeRoute is assigned here in the real code
37
+ });
38
+
39
+ await r.onRouteChange();
40
+ order.push('after-await');
41
+
42
+ // With the fix, handleRoute completes BEFORE the await returns. (Before the
43
+ // fix the awaited promise resolved the instant the timer was scheduled, so
44
+ // 'after-await' would land first — i.e. emit-before-activeRoute.)
45
+ assert.deepEqual(order, ['handleRoute-done', 'after-await']);
46
+ });
47
+
48
+ test('a superseded (debounced) call still resolves — no hang', async () => {
49
+ let handled = 0;
50
+ const r = makeRouter(async () => { handled++; });
51
+
52
+ const p1 = r.onRouteChange(); // schedules timer T1
53
+ const p2 = r.onRouteChange(); // clears T1, resolves p1, schedules T2
54
+
55
+ await Promise.race([
56
+ Promise.all([p1, p2]),
57
+ new Promise((_, rej) => setTimeout(() => rej(new Error('onRouteChange hung')), 1000)),
58
+ ]);
59
+
60
+ // Only the surviving timer runs its work.
61
+ assert.equal(handled, 1);
62
+ });
63
+ });