slicejs-web-framework 3.1.0 → 3.1.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.
package/Slice/Slice.js CHANGED
@@ -132,24 +132,25 @@ export default class Slice {
132
132
 
133
133
  let isVisual = slice.paths.components[componentCategory].type === 'Visual';
134
134
  let modulePath = `${slice.paths.components[componentCategory].path}/${componentName}/${componentName}.js`;
135
+ const isJsOnlyVisualComponent = isVisual && (componentName === 'MultiRoute' || componentName === 'Route');
135
136
 
136
137
  // Load template, class, and CSS concurrently if needed
137
138
  try {
138
139
  // 📦 Skip individual loading if component is available from bundles
139
- const loadTemplate =
140
- isFromBundle || !isVisual || this.controller.templates.has(componentName)
141
- ? Promise.resolve(null)
142
- : this.controller.fetchText(componentName, 'html', componentCategory);
140
+ const loadTemplate =
141
+ isFromBundle || !isVisual || isJsOnlyVisualComponent || this.controller.templates.has(componentName)
142
+ ? Promise.resolve(null)
143
+ : this.controller.fetchText(componentName, 'html', componentCategory);
143
144
 
144
145
  const loadClass =
145
146
  isFromBundle || this.controller.classes.has(componentName)
146
147
  ? Promise.resolve(null)
147
148
  : this.getClass(modulePath);
148
149
 
149
- const loadCSS =
150
- isFromBundle || !isVisual || this.controller.requestedStyles.has(componentName)
151
- ? Promise.resolve(null)
152
- : this.controller.fetchText(componentName, 'css', componentCategory);
150
+ const loadCSS =
151
+ isFromBundle || !isVisual || isJsOnlyVisualComponent || this.controller.requestedStyles.has(componentName)
152
+ ? Promise.resolve(null)
153
+ : this.controller.fetchText(componentName, 'css', componentCategory);
153
154
 
154
155
  const [html, ComponentClass, css] = await Promise.all([loadTemplate, loadClass, loadCSS]);
155
156
 
@@ -0,0 +1,144 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+
4
+ globalThis.alert = () => {};
5
+
6
+ const { default: Slice } = await import('../Slice.js');
7
+
8
+ class FakeController {
9
+ constructor() {
10
+ this.componentCategories = new Map([
11
+ ['MultiRoute', 'Visual'],
12
+ ['Route', 'Visual'],
13
+ ['Link', 'Visual'],
14
+ ['Button', 'Visual']
15
+ ]);
16
+ this.templates = new Map();
17
+ this.classes = new Map();
18
+ this.requestedStyles = new Set();
19
+ this.loadedBundles = new Set();
20
+ this.activeComponents = new Map();
21
+ this.fetchCalls = 0;
22
+ }
23
+
24
+ getBundleForComponent() {
25
+ return null;
26
+ }
27
+
28
+ isComponentFromBundle() {
29
+ return false;
30
+ }
31
+
32
+ async fetchText() {
33
+ this.fetchCalls += 1;
34
+ throw new Error('fetchText should not be called for js-only visual components');
35
+ }
36
+
37
+ verifyComponentIds() {
38
+ return true;
39
+ }
40
+
41
+ registerComponent() {}
42
+
43
+ registerComponentsRecursively() {}
44
+ }
45
+
46
+ class FakeStylesManager {
47
+ registerComponentStyles() {}
48
+ }
49
+
50
+ function createSlice() {
51
+ const instance = new Slice(
52
+ {
53
+ paths: {
54
+ components: {
55
+ Visual: {
56
+ path: '/Components/Visual',
57
+ type: 'Visual'
58
+ }
59
+ }
60
+ },
61
+ themeManager: {},
62
+ stylesManager: {},
63
+ logger: {},
64
+ debugger: { enabled: false },
65
+ loading: {},
66
+ events: {}
67
+ },
68
+ {
69
+ Controller: FakeController,
70
+ StylesManager: FakeStylesManager
71
+ }
72
+ );
73
+
74
+ instance.logger = {
75
+ logError() {},
76
+ logWarning() {},
77
+ logInfo() {}
78
+ };
79
+
80
+ return instance;
81
+ }
82
+
83
+ test('build does not fetch html/css for MultiRoute and Route', async () => {
84
+ const originalSlice = globalThis.slice;
85
+
86
+ try {
87
+ const sliceInstance = createSlice();
88
+ globalThis.slice = sliceInstance;
89
+
90
+ class MultiRouteComponent {
91
+ constructor(props) {
92
+ this.props = props;
93
+ this.sliceId = 'MultiRoute';
94
+ }
95
+ async init() {}
96
+ }
97
+
98
+ class RouteComponent {
99
+ constructor(props) {
100
+ this.props = props;
101
+ this.sliceId = 'Route';
102
+ }
103
+ async init() {}
104
+ }
105
+
106
+ sliceInstance.controller.classes.set('MultiRoute', MultiRouteComponent);
107
+ sliceInstance.controller.classes.set('Route', RouteComponent);
108
+
109
+ const builtMultiRoute = await sliceInstance.build('MultiRoute', {});
110
+ const builtRoute = await sliceInstance.build('Route', {});
111
+
112
+ assert.ok(builtMultiRoute, 'Expected MultiRoute instance to be created');
113
+ assert.ok(builtRoute, 'Expected Route instance to be created');
114
+ assert.equal(sliceInstance.controller.fetchCalls, 0);
115
+ } finally {
116
+ globalThis.slice = originalSlice;
117
+ }
118
+ });
119
+
120
+ test('build still fetches html/css for Link', async () => {
121
+ const originalSlice = globalThis.slice;
122
+
123
+ try {
124
+ const sliceInstance = createSlice();
125
+ globalThis.slice = sliceInstance;
126
+
127
+ class LinkComponent {
128
+ constructor(props) {
129
+ this.props = props;
130
+ this.sliceId = 'Link';
131
+ }
132
+ async init() {}
133
+ }
134
+
135
+ sliceInstance.controller.classes.set('Link', LinkComponent);
136
+
137
+ const builtLink = await sliceInstance.build('Link', {});
138
+
139
+ assert.equal(builtLink, null);
140
+ assert.ok(sliceInstance.controller.fetchCalls > 0, 'Expected Link to trigger resource fetches');
141
+ } finally {
142
+ globalThis.slice = originalSlice;
143
+ }
144
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slicejs-web-framework",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "",
5
5
  "engines": {
6
6
  "node": ">=20"