@codecademy/brand 3.36.2-alpha.be39832dae.0 → 3.36.2-alpha.de5ed068d1.0

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.
@@ -28,6 +28,9 @@ function getPortalOrigin() {
28
28
  // for standard envs, use portal app in the same env
29
29
  if (envs.some(s => `https://${s}.codecademy.com` === origin)) return origin;
30
30
 
31
+ // for PR envs (e.g. pr-40229-monolith.dev-eks.codecademy.com)
32
+ if (origin.includes('.dev-eks.codecademy.com')) return origin;
33
+
31
34
  // for local, use local portal-app, replace if origin port is monolith or le
32
35
  if (origin.includes('localhost')) return origin.replace(/:\d{4}/, ':3100');
33
36
 
@@ -50,19 +53,44 @@ export function serializeSearchWorkerSrc() {
50
53
  // eslint-disable-next-line no-console
51
54
  console.log('[serializeSearchWorkerSrc] Worker function string length:', fnAsStr.length);
52
55
  // eslint-disable-next-line no-console
53
- console.log('[serializeSearchWorkerSrc] First 100 chars:', fnAsStr.substring(0, 100));
56
+ console.log('[serializeSearchWorkerSrc] Full worker function:', fnAsStr);
54
57
 
55
58
  // in a prod build, webpack will handle removing comments
56
59
 
60
+ const startIndex = fnAsStr.indexOf('{');
61
+ // eslint-disable-next-line no-console
62
+ console.log('[serializeSearchWorkerSrc] Start index of first {:', startIndex);
57
63
  const result = fnAsStr.slice(fnAsStr.indexOf('{') + 1, -1) // remove wrapping function, which may have been renamed by minification
58
64
  .replaceAll(' ', '') // remove indentation
59
65
  .replaceAll('{BASE_URL}', BASE_URL) // interpolate base url
60
66
  .replaceAll('{SEARCH}', window.location.search); // interpolate search query
61
67
 
68
+ // Check for external dependencies that would break the worker
69
+ const externalDeps = [];
70
+ if (result.includes('Object(h.a)') || result.includes('h.a')) {
71
+ externalDeps.push('h (Babel async helper)');
72
+ }
73
+ if (result.includes('p.a.mark') || result.includes('p.a.wrap')) {
74
+ externalDeps.push('p (Regenerator runtime)');
75
+ }
76
+ if (result.includes('_createForOfIteratorHelper')) {
77
+ externalDeps.push('_createForOfIteratorHelper (Babel helper)');
78
+ }
79
+ if (externalDeps.length > 0) {
80
+ // eslint-disable-next-line no-console
81
+ console.error('[serializeSearchWorkerSrc] ERROR: Worker code contains external dependencies that will not be available in worker context:', externalDeps);
82
+ // eslint-disable-next-line no-console
83
+ console.error('[serializeSearchWorkerSrc] This is likely because the worker function uses async/await or modern JS features that Babel transpiles with external helpers.');
84
+ // eslint-disable-next-line no-console
85
+ console.error('[serializeSearchWorkerSrc] The worker function needs to be self-contained or the build configuration needs to be adjusted to inline helpers.');
86
+ }
87
+
62
88
  // eslint-disable-next-line no-console
63
89
  console.log('[serializeSearchWorkerSrc] Serialization complete, result length:', result.length);
64
90
  // eslint-disable-next-line no-console
65
- console.log('[serializeSearchWorkerSrc] First 200 chars of result:', result.substring(0, 200));
91
+ console.log('[serializeSearchWorkerSrc] First 500 chars of result:', result.substring(0, 500));
92
+ // eslint-disable-next-line no-console
93
+ console.log('[serializeSearchWorkerSrc] Full result:', result);
66
94
  return result;
67
95
  } catch (error) {
68
96
  // eslint-disable-next-line no-console
@@ -77,11 +105,7 @@ export function serializeSearchWorkerSrc() {
77
105
  * the worker via onmessage and passed back to the main thread via postMessage.
78
106
  */
79
107
  function worker() {
80
- const preloadTitlesPromise = (async () => {
81
- const f = await fetch('{BASE_URL}/autocomplete-preload{SEARCH}');
82
- const rawTitles = await f.json();
83
- return rawTitles.map(preparseTitle);
84
- })();
108
+ const preloadTitlesPromise = fetch('{BASE_URL}/autocomplete-preload{SEARCH}').then(f => f.json()).then(rawTitles => rawTitles.map(preparseTitle));
85
109
  function preparseTitle({
86
110
  value,
87
111
  popularity
@@ -133,41 +157,42 @@ function worker() {
133
157
  };
134
158
  }
135
159
  const maxResults = 5;
136
- async function autocompleteHandler(q) {
137
- const titles = await preloadTitlesPromise;
138
- const scoredTitles = titles.map(t => getScoredTitle(q, t));
139
- const topAutocompleteTitles = scoredTitles.filter(x => x.score > 0).sort((a, b) => a.score > b.score ? -1 : 1).slice(0, maxResults).map(t => ({
140
- title: t.title,
141
- segments: getHighlightSegments(t.title, t.charScores)
142
- }));
143
- postMessage({
144
- query: q.query,
145
- result: topAutocompleteTitles,
146
- action: 'autocomplete'
160
+ function autocompleteHandler(q) {
161
+ preloadTitlesPromise.then(titles => {
162
+ const scoredTitles = titles.map(t => getScoredTitle(q, t));
163
+ const topAutocompleteTitles = scoredTitles.filter(x => x.score > 0).sort((a, b) => a.score > b.score ? -1 : 1).slice(0, maxResults).map(t => ({
164
+ title: t.title,
165
+ segments: getHighlightSegments(t.title, t.charScores)
166
+ }));
167
+ postMessage({
168
+ query: q.query,
169
+ result: topAutocompleteTitles,
170
+ action: 'autocomplete'
171
+ });
147
172
  });
148
173
  }
149
- async function searchAsYouTypeHandler(q) {
150
- const f = await fetch('{BASE_URL}/search-as-you-type{SEARCH}', {
174
+ function searchAsYouTypeHandler(q) {
175
+ fetch('{BASE_URL}/search-as-you-type{SEARCH}', {
151
176
  body: JSON.stringify({
152
177
  query: q.query,
153
178
  max: maxResults
154
179
  }),
155
180
  method: 'POST'
156
- });
157
- const searchAsYouTypeResults = await f.json();
158
- for (const entry of searchAsYouTypeResults.top) {
159
- const t = preparseTitle({
160
- value: entry.title,
161
- popularity: 0
181
+ }).then(f => f.json()).then(searchAsYouTypeResults => {
182
+ for (const entry of searchAsYouTypeResults.top) {
183
+ const t = preparseTitle({
184
+ value: entry.title,
185
+ popularity: 0
186
+ });
187
+ const charScores = getCharScores(q, t);
188
+ entry.segments = getHighlightSegments(entry.title, charScores);
189
+ entry.key = q.query + ':' + entry.title;
190
+ }
191
+ postMessage({
192
+ query: q.query,
193
+ result: searchAsYouTypeResults,
194
+ action: 'search-as-you-type'
162
195
  });
163
- const charScores = getCharScores(q, t);
164
- entry.segments = getHighlightSegments(entry.title, charScores);
165
- entry.key = q.query + ':' + entry.title;
166
- }
167
- postMessage({
168
- query: q.query,
169
- result: searchAsYouTypeResults,
170
- action: 'search-as-you-type'
171
196
  });
172
197
  }
173
198
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecademy/brand",
3
3
  "description": "Brand component library for Codecademy",
4
- "version": "3.36.2-alpha.be39832dae.0",
4
+ "version": "3.36.2-alpha.de5ed068d1.0",
5
5
  "author": "Codecademy Engineering <dev@codecademy.com>",
6
6
  "dependencies": {
7
7
  "@emotion/is-prop-valid": "^1.2.1",