Skip to content

feat: fix the chunk size warning when running vite build (resolves #32)#43

Open
cindyli wants to merge 3 commits intoinclusive-design:mainfrom
cindyli:feat/load-bliss-explanations-json
Open

feat: fix the chunk size warning when running vite build (resolves #32)#43
cindyli wants to merge 3 commits intoinclusive-design:mainfrom
cindyli:feat/load-bliss-explanations-json

Conversation

@cindyli
Copy link
Contributor

@cindyli cindyli commented Jan 13, 2026

  • This pull request has been tested by running npm run test without errors
  • This pull request has been built by running npm run build without errors
  • This isn't a duplicate of an existing pull request

Description

The chunk size warning message at running vite build was caused by importing the large bliss_symbol_explanations.json file. This pull request replace the import with a fetch from a raw github URL. With this fix, the json file is no longer required to be in the /public directory.

I use Chrome to test the load time before and after the fix. The load time is not affected much: 0.32s for before, 0.34s for after.

While working on this issue, I noticed my VS Code editor reports many typescript error complaining the undefined types on many variables. I fixed those in scripts I modified. However, there are more in other scripts.

Steps to test

  1. Run npm start in a terminal
  2. Access the adaptive palette in a browser.

Expected behavior: Make sure all functionality works as is.

@cindyli cindyli requested a review from klown January 13, 2026 22:44
@cindyli cindyli self-assigned this Jan 13, 2026
@cindyli cindyli requested a review from jobara January 15, 2026 19:45
*/
function initCellTypesSelect () {
const cellTypesSelect = document.getElementById("cellTypes");
const cellTypesSelect = document.getElementById("cellTypes") as HTMLSelectElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the as HTMLSelectElement because VSCode's linter complains, where the npm run lint script does not? If so, that's interesting because I frequently find these type errors when writing and running tests. The test(s) fail with an error like cellTypesSelect has no add() method. After I add as HTMLSelectElement, the test runs without that error.

Note: because this is an app-demo script, we decided not the write tests for them, so this was not reported by the test framework either.

labelledBy="slashExampleLabel"
/>
`, document.getElementById("slashExample"));
`, document.getElementById("slashExample") as HTMLElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The as HTMLElement is odd. The type of the second argument of render() is Element since the container can be an HTMLElement, an SVGSVGElement, a MathMLElement and other kinds of Elements. The return type for document.getElementById() is Element. Is this another place where VSCode's linter issued an error? In this case, I don't see why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the Type Assertions docs it would seem that HTMLElement would be inferred anyways. I think this information would be redundant unless there is a desire to be explicit here.

* and create the PaletterStore and NavigationStack objects.
*/
export const adaptivePaletteGlobals = {
interface AdaptivePaletteGlobals {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note to myself: this differs from the feat/integrate-ollama-api-with-palette in that the latter adds a systemPrompts dictionary member to the adaptivePaletteGlobals.

* main paletted Defaults to the
* empty string which denotes
* the `<body>delement.
* the `<body>` element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching my spelling errors and typos. I just noticed some more, a double "the the" above at line 94 and a "paletted" at 95.


export async function loadBlissaryIdMap (): Promise<object> {
const response = await fetch(adaptivePaletteGlobals.blissaryIdMapUrl);
export async function loadDataFromUrl<T>(url: string): Promise<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why the original loadBlissaryIdMap() function was exported since the only place it is used is within GlobalData.ts. Similarly with its replacement loadDataFromUrl(). We should consider not exporting it. What do you think @cindyli ?

paletteDisplay.innerText = "<p>Missing glosses ?</p>";
}
const lookupResults = processPaletteLabels(
const lookupResults = await processPaletteLabels(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The await is not necessary. The following error is output from npm run serveAppsDemos:

  ✘ [ERROR] "await" can only be used inside an "async" function

    apps/palette-generator/palette-generator.ts:126:24:
      126 │   const lookupResults = await processPaletteLabels(

While processPaletteLabels() is actually declared as async, it does not appear to be asynchronous.

* Helper function: Normalizes polymorphic return from decomposeBciAvId
* (value | array | undefined) into (array | undefined)
*/
const normalizeToOptionalArray = (val: unknown): (string | number)[] | undefined => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool. We might want to move this or some form of it to the GlobalUtils.ts. There are many places where I've had to add checks for a given BciAvIdType variable to see if it was the array or the number form and branch accordingly. I've often thought that there has to be a better way.

};

/**
* Helper function: Compares two arrays for equality safely
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "Helper function: Compare two arrays for equality safely, where each item in the array is either a string or a number". What do you think?

const wordMatch = new RegExp("\\b" + label + "\\b");

if (label === gloss.description || wordMatch.test(gloss.description)) {
const glossId = typeof gloss.id === "number" ? gloss.id : parseInt(gloss.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that the check for a "number" type is needed. According to MDN, parseInt() first converts its argument to a string and then parses that. So passing an actual number is fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also want to include the radix parameter to be explicit about what base the number has.

});
console.log(`\tFound match: ${gloss.description}, bci-av-id: ${gloss.id}`);

console.log(`\tFound match: ${gloss.description}, bci-av-id: ${glossId}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding glossId in this log statement: what is the reason to use a number, where before it used the original string value gloss.id?

Comment on lines +23 to +28
let bciAvSymbolsDict: BciAvSymbolsDict = [];

// Load the BCI AV symbols dictionary from the URL
export async function loadBciAvSymbolsDict() {
bciAvSymbolsDict = await loadDataFromUrl<BciAvSymbolsDict>(bciAvSymbolsDictUrl);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about this approach for a specific load function. It seem there are other functions in this file that also require the symbols.

I thought that import caches, so it only happens once across all the files. Does fetch also cache?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about caching. I do know that a dynamic import using the import(...) function is implemented as fetch(), ultimately. Maybe static import is also implemented as fetch? In this case, the result of loadDataFromUrl() is stored in the variable bciAvSymbolsDict, which is how other functions within the file get access to the symbols. That variable is within the memory space of the web page -- is that memory cached anywhere?

The main reason for replacing static import with fetch is to avoid the build warning message that some chunks are too big. The build process puts data that is imported statically into the dist folder hierarchy. That does not happen for data that is accessed via fetch().

PS. In this case (line 27), loadDataFromUrl() is not replacing a static import. It's replacing a direct call to fetch(), if that matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants