Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ module.exports = (api) => {
// we require polyfills for this already
'Array.prototype.includes',

// Used only in Chat, which expects modern browsers
'Object.fromEntries',
'Object.entries',

// false positive (babel doesn't know types)
// this is actually only called on arrays
'String.prototype.includes',
Expand Down
4 changes: 2 additions & 2 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
},
{
"path": "./packages/instantsearch.js/dist/instantsearch.production.min.js",
"maxSize": "91.5 kB"
"maxSize": "122.25 kB"
},
{
"path": "./packages/instantsearch.js/dist/instantsearch.development.js",
"maxSize": "200 kB"
"maxSize": "242 kB"
},
{
"path": "packages/react-instantsearch-core/dist/umd/ReactInstantSearchCore.min.js",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-uglify": "6.0.4",
"rollup-plugin-alias": "2.2.0",
"shelljs": "0.8.5",
"shipjs": "0.26.0",
"ts-jest": "27",
Expand Down
5 changes: 3 additions & 2 deletions packages/instantsearch.js/.storybook/decorators/withHits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {
liteClient as namedConstructor,
default as defaultConstructor,
} from 'algoliasearch/lite';
import instantsearch from '../../src';
import instantsearch from '../../src/index.es';
import defaultPlayground from '../playgrounds/default';
import {
InstantSearch,
InstantSearchOptions,
SearchClient,
} from '../../src/types';
import configure from '../../src/widgets/configure/configure';

const algoliasearch = (namedConstructor || defaultConstructor) as unknown as (
appId: string,
Expand Down Expand Up @@ -81,7 +82,7 @@ export const withHits =
});

search.addWidgets([
instantsearch.widgets.configure({
configure({
hitsPerPage: 4,
attributesToSnippet: ['description:15'],
snippetEllipsisText: '[…]',
Expand Down
19 changes: 19 additions & 0 deletions packages/instantsearch.js/scripts/rollup/emptyModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Placeholder export for 'zod' module
export const ZodFirstPartyTypeKind = {};
export const toJSONSchema = {};
export const safeParseAsync = {};
export const z = new Proxy(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

at which point is this evaluated? do we need to check if proxy exists first in case it gets evaluated in IE11?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm ok with chat not working in IE11, but just ensuring that the entire InstantSearch doesn't throw

Copy link
Member

Choose a reason for hiding this comment

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

Yeah the constructor does get called directly. There are polyfills though if we still actually care about the tests passing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may need to do typeof Proxy === 'object' ? new Proxy : null or similar to at least not have a global error thrown then? not sure how to check tbh, just asking

Copy link
Member

Choose a reason for hiding this comment

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

It would still throw though cause zod schemas are created when the script is evaluated... so we'd have to define all those functions just for IE11 to work and make the bundle bigger

{},
{
get: (_, name) =>
name === '~standard'
? { validate: (value) => Promise.resolve({ issues: null, value }) }
: function () {
return this;
},
}
);

// Placeholder export for 'react' module
export const cloneElement = {};
export const createElement = {};
22 changes: 22 additions & 0 deletions packages/instantsearch.js/scripts/rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import path from 'path';

import alias from 'rollup-plugin-alias';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
Expand All @@ -16,6 +19,25 @@ const link = 'https://github.com/algolia/instantsearch';
const license = `/*! InstantSearch.js ${version} | ${algolia} | ${link} */`;

const plugins = [
alias({
entries: [
{
find: /^zod.*/,
replacement: path.join(__dirname, './emptyModule.js'),
},
{
find: /^react.*/,
replacement: path.join(__dirname, './emptyModule.js'),
},
{
find: 'eventsource-parser/stream',
replacement: path.join(
__dirname,
'../../../../node_modules/eventsource-parser/dist/stream.js'
),
},
],
}),
resolve({
browser: true,
preferBuiltins: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/instantsearch.js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as connectors from './connectors/index.umd';
import * as connectors from './connectors/index';
import * as helpers from './helpers/index';
import { createInfiniteHitsSessionStorageCache } from './lib/infiniteHitsCache/index';
import InstantSearch from './lib/InstantSearch';
Expand All @@ -7,7 +7,7 @@ import * as stateMappings from './lib/stateMappings/index';
import version from './lib/version';
import * as middlewares from './middlewares/index';
import * as templates from './templates/index';
import * as widgets from './widgets/index.umd';
import * as widgets from './widgets/index';

import type { InstantSearchOptions } from './lib/InstantSearch';
import type { Expand, UiState } from './types';
Expand Down
3 changes: 2 additions & 1 deletion tests/umd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('UMD bundle', () => {
name: 'instantsearch.js',
bundle: 'dist/instantsearch.production.min.js',
globalName: 'instantsearch',
unavailable: ['connectors.connectChat', 'widgets.chat'],
},
{
name: 'react-instantsearch-core',
Expand Down Expand Up @@ -124,6 +123,8 @@ async function createEnvironment(
resources: 'usable',
});

window.TransformStream = TransformStream;

const error = jest.fn();
window.addEventListener('error', error);

Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28367,6 +28367,13 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^2.0.0"
inherits "^2.0.1"

[email protected]:
version "2.2.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-alias/-/rollup-plugin-alias-2.2.0.tgz#5004a2bc542a2eebb45b5a0fff8c6f540439decc"
integrity sha512-9ZK410qeFed4gGrHoojBpxLsHF74vPgsheGg9JRW5RbALAxqdvJbd357mSqWBqUrBfRVnZnNUXTZdYLxxQEA5A==
dependencies:
slash "^3.0.0"

[email protected]:
version "4.3.3"
resolved "https://registry.yarnpkg.com/rollup-plugin-babel/-/rollup-plugin-babel-4.3.3.tgz#7eb5ac16d9b5831c3fd5d97e8df77ba25c72a2aa"
Expand Down