Skip to content

Commit

Permalink
perf: update to support SSR
Browse files Browse the repository at this point in the history
This commit addresses some issues when it comes to supporting SSR in
Svelte. The renaming of files to .js to .mjs isn't necessary. The SSR
build cycle simply does not like non-descript file names, so by default
every reference needs to have at least .js and that will work.

An additional update is to wrap an if statement around the window object
request. The SSR environment has no ref to window and thus does not
understand this request. Wrapping an if window is defined allows the SSR
build to bypass that that function.

Changes to be committed:
modified:   index.js
modified:   package.json
renamed:    src/auro-input.mjs -> src/auro-input.js
renamed:    src/base-input.mjs -> src/base-input.js
renamed:    src/i18n.mjs -> src/i18n.js
modified:   test/auro-input.test.js
  • Loading branch information
blackfalcon committed Feb 10, 2024
1 parent c18c290 commit fa45148
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AuroInput } from './src/auro-input.mjs';
import { AuroInput } from './src/auro-input.js';

/**
* Register Custom Element.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
],
"scripts": {
"build": "npm-run-all build:sass sass:render dist:js build:api test build:docs bundler postinstall types",
"build:api": "wca analyze 'src/auro-input.mjs' --outFiles docs/api.md",
"build:api": "wca analyze 'src/auro-input.js' --outFiles docs/api.md",
"build:demo": "npm-run-all build demo:rm:build demo:new:build demo:copy:index demo:copy:demo demo:update:index",
"build:dev:assets": "npm-run-all build:sass:component postCss:component sass:render",
"build:docs": "node scripts/generateDocs.mjs",
Expand Down
4 changes: 2 additions & 2 deletions src/auro-input.mjs → src/auro-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { html } from "lit";
import { repeat } from 'lit/directives/repeat.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import i18n from './i18n.mjs';
import BaseInput from './base-input.mjs';
import i18n from './i18n.js';
import BaseInput from './base-input.js';

// build the component class
export class AuroInput extends BaseInput {
Expand Down
2 changes: 1 addition & 1 deletion src/base-input.mjs → src/base-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import viewPassword from '@alaskaairux/icons/dist/icons/interface/view-password.
import hidePassword from '@alaskaairux/icons/dist/icons/interface/hide-password.mjs';
import alert from '@alaskaairux/icons/dist/icons/alert/error.mjs';
import Cleave from 'cleave.js';
import i18n, {notifyOnLangChange, stopNotifyingOnLangChange} from './i18n.mjs';
import i18n, {notifyOnLangChange, stopNotifyingOnLangChange} from './i18n.js';

/**
* Auro-input provides users a way to enter data into a text field.
Expand Down
10 changes: 6 additions & 4 deletions src/i18n.mjs → src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ function handleChange(mutationList) {
});
}

if (window.MutationObserver) {
const observer = new MutationObserver(handleChange);
observer.observe(document.documentElement, { attributes: true,
attributeFilter: ['lang'] });
if (typeof window !== "undefined") {
if (window.MutationObserver) {
const observer = new MutationObserver(handleChange);
observer.observe(document.documentElement, { attributes: true,
attributeFilter: ['lang'] });
}
}

const stringsES = {
Expand Down
2 changes: 1 addition & 1 deletion test/auro-input.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fixture, html, expect, elementUpdated, oneEvent } from '@open-wc/testing';
import '../src/auro-input.mjs';
import '../src/auro-input.js';

describe('auro-input', () => {

Expand Down

0 comments on commit fa45148

Please sign in to comment.