Skip to content

Commit

Permalink
Workaround: calling useVingKind().all() when doing an SSR without a m…
Browse files Browse the repository at this point in the history
…iddleware causes Nuxt to crash #168
  • Loading branch information
rizen committed Jun 25, 2024
1 parent 80d102b commit d8dfdc2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/composables/ving/useRest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export default async function (url, behavior = {}) {
query: behavior.query,
body: behavior.body,
headers: {
...useRequestHeaders(),
//...useRequestHeaders(),
cookie: useRequestHeader('cookie'), // see https://github.com/plainblack/ving/issues/168
...behavior.headers
},
async onRequest(context) {
Expand Down
3 changes: 2 additions & 1 deletion app/composables/ving/useVingKind.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class VingKind {
/**
* Retrieves all the records for the given configuration.
*
* NOTE: This method should not be called on a page that has no nuxt middleware such as `auth`. If you need to, then use the `all-workaround` middlware provided. See https://github.com/plainblack/ving/issues/168
*
* @param {Object} options An object for modifying the the method's functionality. See `search` for more info.
* @param {Function} options.onAllDone An optional callback that will be called when all the requests have been processed.
* @example
Expand All @@ -101,7 +103,6 @@ class VingKind {
async all(options = {}) {
let totalPages = 1;
for (let pageNo = 1; pageNo <= totalPages; pageNo++) {
console.log(pageNo)
await this.search({
...options,
accumulate: true,
Expand Down
7 changes: 7 additions & 0 deletions app/middleware/all-workaround.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Use this if you're trying to use useVingKind() with an .all() call and you don't have another middleware that you need to run on that page.
* @see https://github.com/plainblack/ving/issues/168
*/
export default defineNuxtRouteMiddleware(async () => {
await $fetch(`/api/v1/test`);
});
1 change: 1 addition & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ outline: deep

### 2024-06-25
* Disabled nuxt devtools, because I never use them and they are spewing junk into the console.
* Workaround: calling useVingKind().all() when doing an SSR without a middleware causes Nuxt to crash #168

### 2024-06-24
* Fixed: pager appears to be broken #167
Expand Down

0 comments on commit d8dfdc2

Please sign in to comment.