Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat: server side rendering #596

Merged
merged 72 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
0a91be9
chore: update lockfile
Haroenv Nov 14, 2018
d1f30aa
chore: add initial ssr example (no Algolia)
Haroenv Nov 14, 2018
31a23d0
chore: redo SSR via vue cli & add algolia page
Haroenv Nov 14, 2018
6f19944
temp commit
Haroenv Nov 27, 2018
6b03dcf
chore(lint): allow $_ais
Haroenv Nov 30, 2018
6f0aa78
feat(ssr): split up components
Haroenv Nov 30, 2018
28f2141
refactor(ssr): factorise example usage
Haroenv Nov 30, 2018
34f1864
fix: call render once on client to give state before render
Haroenv Nov 30, 2018
61283ac
chore: remove log
Haroenv Nov 30, 2018
6cea2f5
chore: set default params to avoid highlight not working
Haroenv Dec 20, 2018
08e4547
Merge branch 'v2' into feat/ssr-2
Haroenv Dec 20, 2018
2d11dce
chore: fix tests
Haroenv Jan 4, 2019
7cc6347
chore: no linting on ssr example until we are done
Haroenv Jan 4, 2019
1d8ad1d
fix: make sure it works with complex components
Haroenv Jan 4, 2019
57f6b38
chore: rename ais-ssr to ais-instant-search-ssr
Haroenv Jan 4, 2019
dbb327c
docs: refinement-list in example
Haroenv Jan 4, 2019
29985bf
fix: correct name for ais-instant-search-ssr
Haroenv Jan 4, 2019
d76526e
feat: throw warning when SSR and no injection
Haroenv Jan 4, 2019
2d24fd3
test(ssr): initial component
Haroenv Jan 4, 2019
eeab9de
feat: rename all SSR methods
Haroenv Jan 4, 2019
9a766b5
chore(ssr): small logic refactor of name
francoischalifour Jan 14, 2019
e56eaf0
chore: make linting pass
Haroenv Jan 14, 2019
64f08b9
Merge branch 'v2' into feat/ssr-2
Haroenv Jan 14, 2019
be01e04
refactor(ssr): rename internal file
Haroenv Jan 14, 2019
13f15ed
chore: remove helper-serializer
Haroenv Jan 14, 2019
7a03b60
chore(build): allow spread
Haroenv Jan 14, 2019
7112e56
chore(example): kebab
Haroenv Jan 14, 2019
59fe667
feat(ssr): move monkeypatching inside code
Haroenv Jan 14, 2019
e2dcd51
docs(example): pagination
Haroenv Jan 14, 2019
49f0d2e
test(ssr): write tests for all injection functions
Haroenv Jan 14, 2019
2eb8bdc
chore: downgrade node
Haroenv Jan 14, 2019
788e2ab
chore(babel): allow spread in storybook
Haroenv Jan 15, 2019
adccbd9
docs(ssr): add Nuxt example (#603)
Haroenv Jan 17, 2019
a06b011
Merge branch 'v2' into feat/ssr-2
Haroenv Jan 17, 2019
9382230
fix(test): avoid broken dependency injection
Haroenv Jan 17, 2019
2e4fe4f
refactor(ssr): remove findRoot
Haroenv Jan 17, 2019
3756970
refactor(ssr): findResultsState returns nothing, introduce getState
Haroenv Jan 17, 2019
caecdfd
docs(example): update code
Haroenv Jan 17, 2019
012a198
chore(examples): remove unused sample files
Haroenv Jan 18, 2019
4ada1be
docs(example-ssr): make use of correct state var
Haroenv Jan 18, 2019
5a54238
fix(ssr): move getState error to warning
Haroenv Jan 18, 2019
772b363
chore(example): lint
Haroenv Jan 18, 2019
638e05b
fix(ssr): prevent overriding of forced parameters
Haroenv Jan 18, 2019
7528ea5
chore(ssr): improve test wording
Haroenv Jan 18, 2019
916d289
docs(ssr): add explaining comment on searchOnce
Haroenv Jan 18, 2019
23b65ac
fix(babel): use _objectSpread from babel instead of Object.assign
Haroenv Jan 18, 2019
f9a9dcb
refactor(ais-instant-search): move from pure factory function to augm…
Haroenv Jan 18, 2019
1ec0497
chore(rollup): remove spread
Haroenv Jan 18, 2019
9550e01
chore(babel): remove spread
Haroenv Jan 18, 2019
b069866
chore(nuxt): simpler example
Haroenv Jan 18, 2019
c9d1957
chore(examples): avoid lint for now (prettier conflicts)
Haroenv Jan 18, 2019
858d256
chore(nuxt): easier example
Haroenv Jan 18, 2019
7c0c364
chore(ssr-example): only hydrate if possible
Haroenv Jan 18, 2019
c4e3b91
fix(ssr): only __forceRender once on server, once on client
Haroenv Jan 18, 2019
852ea13
fix(core): prevent instance from starting multiple times (#607)
Haroenv Jan 18, 2019
ab21074
Merge branch 'v2' into feat/ssr-2
Haroenv Jan 18, 2019
352d1eb
chore(build): fix indention
Haroenv Jan 21, 2019
341ade4
refactor(ssr): getState shouldn't warn if early
Haroenv Jan 21, 2019
65dd111
test(mock): remove global _stalledSearchDelay
Haroenv Jan 21, 2019
ed9208d
chore(example): add vue-instantsearch via npm
Haroenv Jan 21, 2019
6d3b4aa
chore(nuxt): consistent state naming
Haroenv Jan 21, 2019
43a2bab
test(cis): better naming
Haroenv Jan 21, 2019
608bbdf
refactor(CISC): move spreading into util
Haroenv Jan 21, 2019
dd842ba
refactor(cis): createInstantSearch has same signature as regular inst…
Haroenv Jan 21, 2019
1ee5b13
fix(destroy): set helper to null to avoid old requests
Haroenv Jan 21, 2019
d574d61
chore: remove unused import
Haroenv Jan 21, 2019
f3c2b11
fix(ssr): review of error messages
francoischalifour Jan 21, 2019
1367a73
chore(errors): fix typo
Haroenv Jan 21, 2019
56c4ef9
chore(lint): prettier
Haroenv Jan 22, 2019
4f54334
chore(jest): fix static mock
Haroenv Jan 22, 2019
cda2ac8
fix(core): set hydrated to false on destroy
Haroenv Jan 22, 2019
8d339a1
fix(ssr): do not allow instance to start multiple times
Haroenv Jan 23, 2019
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
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015"]
presets: ['es2015'],
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ yarn-error.log
node_modules/
coverage
.DS_store
.nuxt
49 changes: 49 additions & 0 deletions __mocks__/instantsearch-es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-disable import/no-commonjs */
const isPlainObject = require('lodash/isPlainObject');

class RoutingManager {
constructor(routing) {
this._routing = routing;
}
}

class Helper {
constructor() {
this.search = jest.fn();
this.setClient = jest.fn(() => this);
this.setIndex = jest.fn(() => this);
}
}

const fakeInstantSearch = jest.fn(
({
indexName,
searchClient,
routing,
stalledSearchDelay,
searchFunction,
}) => {
if (!searchClient && !isPlainObject(searchClient)) {
throw new Error('need searchClient to be a plain object');
}
if (!indexName) {
throw new Error('need indexName to be a string');
}

const instantsearchInstance = {
_stalledSearchDelay: stalledSearchDelay || 200,
_searchFunction: searchFunction,
routing: new RoutingManager(routing),
helper: new Helper(),
client: searchClient,
start: jest.fn(() => {
instantsearchInstance.started = true;
}),
dispose: jest.fn(),
};

return instantsearchInstance;
}
);

module.exports = fakeInstantSearch;
12 changes: 8 additions & 4 deletions examples/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ cd $(dirname `which $0`)

for dir in ./* ; do
if [ -d "$dir" ]; then
name=$(basename "$dir")
echo "building example: $name"
cd $name
name=$(basename "$dir")
echo "building example: $name"
cd $name
if [[ "$name" != "nuxt" && "$name" != "ssr" ]]; then
yarn
yarn build
cp -R dist ../../docs/dist/examples/$name
cd ..
else
echo "build of $name skipped"
fi
cd ..
fi
done

Expand Down
22 changes: 22 additions & 0 deletions examples/nuxt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# nuxt

> Vue InstantSearch & Nuxt

## Build Setup

``` bash
# install dependencies
$ yarn install

# serve with hot reload at localhost:3000
$ yarn run dev

# build for production and launch server
$ yarn run build
$ yarn start

# generate static project
$ yarn run generate
```

For detailed explanation on how things work, checkout [Nuxt.js docs](https://nuxtjs.org).
7 changes: 7 additions & 0 deletions examples/nuxt/layouts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# LAYOUTS

**This directory is not required, you can delete it if you don't want to use it.**

This directory contains your Application Layouts.

More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts).
26 changes: 26 additions & 0 deletions examples/nuxt/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div>
<div id="nav">
<nuxt-link to="/">Home</nuxt-link> |
<nuxt-link to="/search">Search</nuxt-link>
</div>
<nuxt />
</div>
</template>

<style>
html {
font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI',
Roboto, sans-serif;
}

*,
*:before,
*:after {
box-sizing: border-box;
}

#nav {
text-align: center;
}
</style>
48 changes: 48 additions & 0 deletions examples/nuxt/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable import/no-commonjs */
const pkg = require('./package');

module.exports = {
mode: 'universal',

/*
** Headers of the page
*/
head: {
title: pkg.name,
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: pkg.description },
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
},

/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },

/*
** Global CSS
*/
css: [],

/*
** Plugins to load before mounting the App
*/
plugins: [],

/*
** Nuxt.js modules
*/
modules: [],

/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
},
};
21 changes: 21 additions & 0 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "nuxt",
"version": "1.0.0",
"description": "Vue InstantSearch & Nuxt",
"private": true,
"scripts": {
"dev": "nuxt",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"algoliasearch": "^3.32.0",
"cross-env": "^5.2.0",
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
"nuxt": "^2.0.0",
"vue-instantsearch": "^2.0.0-beta.2"
},
"devDependencies": {
"nodemon": "^1.11.0"
}
}
6 changes: 6 additions & 0 deletions examples/nuxt/pages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# PAGES

This directory contains your Application Views and Routes.
The framework reads all the `*.vue` files inside this directory and create the router of your application.

More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing).
11 changes: 11 additions & 0 deletions examples/nuxt/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<h2>
Go to the search page: <nuxt-link to="/search">"/search"</nuxt-link>
</h2>
</template>

<style>
h2 {
text-align: center;
}
</style>
102 changes: 102 additions & 0 deletions examples/nuxt/pages/search.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<template>
<ais-instant-search-ssr>
<ais-search-box />
<ais-stats />
<ais-refinement-list attribute="genre" />
<ais-hits>
<template
slot="item"
slot-scope="{ item }"
>
<ais-highlight
attribute="title"
:hit="item"
/>
<p class="year">{{ item.year }}</p>
<p class="genre">
<span
v-for="genre in item.genre"
:key="genre"
class="badge"
>
{{ genre }}
</span>
</p>
</template>
</ais-hits>
<ais-pagination />
</ais-instant-search-ssr>
</template>

<script>
import {
AisInstantSearchSsr,
AisRefinementList,
AisHits,
AisHighlight,
AisSearchBox,
AisStats,
AisPagination,
createInstantSearch,
} from '../../../src/instantsearch'; // TODO: move this to 'vue-instantsearch'
import algoliasearch from 'algoliasearch/lite';

const searchClient = algoliasearch(
'latency',
'6be0576ff61c053d5f9a3225e2a90f76'
);

const { instantsearch, rootMixin } = createInstantSearch({
searchClient,
indexName: 'movies',
});

export default {
asyncData() {
return instantsearch
.findResultsState({
query: 'hi',
hitsPerPage: 5,
disjunctiveFacets: ['genre'],
disjunctiveFacetsRefinements: { genre: ['Comedy'] },
})
.then(() => ({
algoliaState: instantsearch.getState(),
}));
},
beforeMount() {
// Nuxt will merge `asyncData` and `data` on the client
instantsearch.hydrate(this.algoliaState);
},
mixins: [rootMixin],
components: {
AisInstantSearchSsr,
AisRefinementList,
AisHits,
AisHighlight,
AisSearchBox,
AisStats,
AisPagination,
},
head() {
return {
link: [
{
rel: 'stylesheet',
href:
'https://unpkg.com/instantsearch.css@7.1.0/themes/algolia-min.css',
},
],
};
},
};
</script>

<style>
.ais-Hits-list {
text-align: left;
}
.ais-InstantSearch {
margin: 1em;
}
</style>
10 changes: 10 additions & 0 deletions examples/nuxt/static/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# STATIC

**This directory is not required, you can delete it if you don't want to use it.**

This directory contains your static files.
Each file inside this directory is mapped to `/`.

Example: `/static/robots.txt` is mapped as `/robots.txt`.

More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#static).
Binary file added examples/nuxt/static/favicon.ico
Binary file not shown.
Loading