Skip to content

Commit

Permalink
Merge latest changes from main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
SeppahBaws committed Aug 19, 2024
2 parents 3596843 + 677e2d1 commit 9aa1de7
Show file tree
Hide file tree
Showing 39 changed files with 1,172 additions and 417 deletions.
5 changes: 0 additions & 5 deletions .changeset/eighty-fishes-shake.md

This file was deleted.

1 change: 0 additions & 1 deletion e2e/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"build:": "cd ../../ && ((pnpm run build && cd -) || (cd - && exit 1))",
"build:dev": "pnpm build: && pnpm dev",
"build:web": "pnpm build: && pnpm web",
"build:test": "pnpm build: && pnpm test",
"build:generate": "pnpm build: && pnpm houdini generate",
"build:build": "pnpm build: && pnpm build",
Expand Down
21 changes: 21 additions & 0 deletions e2e/react/src/routes/optimistic-keys/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,24 @@ test('@optimisticKey', async ({ page }) => {
// the value in the last row should be 'final value'
expect(await getValue()).toBe('final value')
})

test('@optimisticKey - double click', async ({ page }) => {
await goto(page, routes.optimistic_keys)

// all we have to do is double click twice and make sure we didn't get an error when it resolves
await page.click('[data-test-action="create"]')
await page.click('[data-test-action="create"]')

// wait a few seconds and make sure there are no errors
await sleep(300)

// wait a few seconds and make sure there are no errors
await sleep(300)
let found = false
try {
await page.waitForSelector('h1', { timeout: 100 })
found = true
} catch {}

expect(found).toBe(false)
})
14 changes: 14 additions & 0 deletions packages/adapter-auto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# houdini-adapter-auto

## 1.2.55

### Patch Changes

- Updated dependencies [[`98859e78`](https://github.com/HoudiniGraphql/houdini/commit/98859e78e088cf733edc35b3ad96b1a1f9f48b79), [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8)]:
- houdini@1.2.55

## 1.2.54

### Patch Changes

- Updated dependencies []:
- houdini@1.2.54

## 1.2.53

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-auto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-adapter-auto",
"version": "1.2.53",
"version": "1.2.55",
"description": "An adapter for deploying your Houdini application according to the build environment ",
"keywords": [
"houdini",
Expand Down
14 changes: 14 additions & 0 deletions packages/adapter-cloudflare/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# houdini-adapter-cloudflare

## 1.2.55

### Patch Changes

- Updated dependencies [[`98859e78`](https://github.com/HoudiniGraphql/houdini/commit/98859e78e088cf733edc35b3ad96b1a1f9f48b79), [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8)]:
- houdini@1.2.55

## 1.2.54

### Patch Changes

- Updated dependencies []:
- houdini@1.2.54

## 1.2.53

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-adapter-cloudflare",
"version": "1.2.53",
"version": "1.2.55",
"description": "The adapter for deploying your Houdini application to Cloudflare Pages",
"keywords": [
"houdini",
Expand Down
14 changes: 14 additions & 0 deletions packages/adapter-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# houdini-adapter-node

## 1.2.55

### Patch Changes

- Updated dependencies [[`98859e78`](https://github.com/HoudiniGraphql/houdini/commit/98859e78e088cf733edc35b3ad96b1a1f9f48b79), [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8)]:
- houdini@1.2.55

## 1.2.54

### Patch Changes

- Updated dependencies []:
- houdini@1.2.54

## 1.2.53

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-adapter-node",
"version": "1.2.53",
"version": "1.2.55",
"description": "The adapter for deploying your Houdini application as a standalone node server",
"keywords": [
"houdini",
Expand Down
14 changes: 14 additions & 0 deletions packages/adapter-static/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# houdini-adapter-static

## 1.2.55

### Patch Changes

- Updated dependencies [[`98859e78`](https://github.com/HoudiniGraphql/houdini/commit/98859e78e088cf733edc35b3ad96b1a1f9f48b79), [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8)]:
- houdini@1.2.55

## 1.2.54

### Patch Changes

- Updated dependencies []:
- houdini@1.2.54

## 1.2.53

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-static/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-adapter-static",
"version": "1.2.53",
"version": "1.2.55",
"description": "The adapter for deploying your Houdini application as a single-page application without a server component",
"keywords": [
"houdini",
Expand Down
4 changes: 4 additions & 0 deletions packages/create-houdini/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# create-houdini

## 1.2.55

## 1.2.54

## 1.2.53

## 1.2.52
Expand Down
2 changes: 1 addition & 1 deletion packages/create-houdini/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-houdini",
"version": "1.2.53",
"version": "1.2.55",
"description": "A CLI for creating new Houdini projects",
"repository": {
"type": "git",
Expand Down
16 changes: 16 additions & 0 deletions packages/houdini-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# houdini-react

## 1.2.55

### Patch Changes

- [#1337](https://github.com/HoudiniGraphql/houdini/pull/1337) [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Various fixes for optimistic use cases

- Updated dependencies [[`98859e78`](https://github.com/HoudiniGraphql/houdini/commit/98859e78e088cf733edc35b3ad96b1a1f9f48b79), [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8)]:
- houdini@1.2.55

## 1.2.54

### Patch Changes

- Updated dependencies []:
- houdini@1.2.54

## 1.2.53

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-react",
"version": "1.2.53",
"version": "1.2.55",
"description": "The React plugin for houdini",
"keywords": [
"typescript",
Expand Down
16 changes: 16 additions & 0 deletions packages/houdini-svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# houdini-svelte

## 1.2.55

### Patch Changes

- Updated dependencies [[`98859e78`](https://github.com/HoudiniGraphql/houdini/commit/98859e78e088cf733edc35b3ad96b1a1f9f48b79), [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8)]:
- houdini@1.2.55

## 1.2.54

### Patch Changes

- [#1334](https://github.com/HoudiniGraphql/houdini/pull/1334) [`a4fac956`](https://github.com/HoudiniGraphql/houdini/commit/a4fac95634584d38f9e78329fc69b1bd8cc2412d) Thanks @fnimick! - Fix filesystem patches to not use illegal paths

- Updated dependencies []:
- houdini@1.2.54

## 1.2.53

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini-svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini-svelte",
"version": "1.2.53",
"version": "1.2.55",
"description": "The svelte plugin for houdini",
"keywords": [
"typescript",
Expand Down
10 changes: 10 additions & 0 deletions packages/houdini/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# houdini

## 1.2.55

### Patch Changes

- [#1339](https://github.com/HoudiniGraphql/houdini/pull/1339) [`98859e78`](https://github.com/HoudiniGraphql/houdini/commit/98859e78e088cf733edc35b3ad96b1a1f9f48b79) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Fix circular import in generated runtime

- [#1337](https://github.com/HoudiniGraphql/houdini/pull/1337) [`5add29a6`](https://github.com/HoudiniGraphql/houdini/commit/5add29a68489fd9382d0809cf574a1db2746aae8) Thanks [@AlecAivazis](https://github.com/AlecAivazis)! - Various fixes for optimistic use cases

## 1.2.54

## 1.2.53

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "houdini",
"version": "1.2.53",
"version": "1.2.55",
"description": "The disappearing GraphQL clients",
"keywords": [
"typescript",
Expand Down
65 changes: 49 additions & 16 deletions packages/houdini/src/runtime/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ListManager } from './lists'
import { StaleManager } from './staleManager'
import type { Layer, LayerID } from './storage'
import { InMemoryStorage } from './storage'
import { evaluateKey } from './stuff'
import { evaluateKey, rootID } from './stuff'
import { InMemorySubscriptions, type FieldSelection } from './subscription'

export class Cache {
Expand Down Expand Up @@ -146,21 +146,28 @@ export class Cache {
}

// when an optimistic key resolves, we might momentarily know the same record by different IDs
registerKeyMap(source: string | number, mapped: string | number) {
registerKeyMap(source: string, mapped: string) {
this._internal_unstable.storage.registerIDMapping(source, mapped)
this._internal_unstable.subscriptions.copySubscribers(source, mapped)
}

// remove the record from the cache's store and unsubscribe from it
delete(id: string, layer?: Layer) {
// clean up any subscribers associated with the record before we destroy the actual values that will let us
// walk down
this._internal_unstable.subscriptions.removeAllSubscribers(id)
const recordIDs = [this._internal_unstable.storage.idMaps[id], id].filter(
Boolean
) as string[]

// make sure we remove the id from any lists that it appears in
this._internal_unstable.lists.removeIDFromAllLists(id, layer)
for (const recordID of recordIDs) {
// clean up any subscribers associated with the record before we destroy the actual values that will let us
// walk down
this._internal_unstable.subscriptions.removeAllSubscribers(recordID)

// delete the record from the store
this._internal_unstable.storage.delete(id, layer)
// make sure we remove the id from any lists that it appears in
this._internal_unstable.lists.removeIDFromAllLists(recordID, layer)

// delete the record from the store
this._internal_unstable.storage.delete(recordID, layer)
}
}

// set the cache's config
Expand Down Expand Up @@ -702,6 +709,12 @@ class CacheInternal {
forceNotify,
})

// we have to do something different if we are writing to an optimistic layer or not
let action = () => {
// update the cached value
layer.writeLink(parent, key, linkedIDs)
}

// if we're supposed to apply this write as an update, we need to figure out how
if (applyUpdates && updates) {
// if we are updating the edges field, we might need to do a little more than just
Expand Down Expand Up @@ -738,7 +751,6 @@ class CacheInternal {
// look up the node reference
const { value } = this.storage.get(id, 'node')
const node = value as string

// if the id is being adding and is part of the empty edges, don't include it
if (newNodeIDs.includes(node) && emptyEdges.includes(node)) {
return false
Expand All @@ -759,10 +771,28 @@ class CacheInternal {
// if we have to prepend it, do so
if (update === 'prepend') {
linkedIDs = newIDs.concat(oldIDs as (string | null)[])
if (layer?.optimistic) {
action = () => {
for (const id of newIDs) {
if (id) {
layer.insert(parent, key, 'start', id)
}
}
}
}
}
// otherwise we might have to append it
else if (update === 'append') {
linkedIDs = oldIDs.concat(newIDs)
if (layer?.optimistic) {
action = () => {
for (const id of newIDs) {
if (id) {
layer.insert(parent, key, 'end', id)
}
}
}
}
}
// if the update is a replace do the right thing
else if (update === 'replace') {
Expand Down Expand Up @@ -798,8 +828,7 @@ class CacheInternal {

// if there was a change in the list
if (contentChanged || (oldIDs.length === 0 && newIDs.length === 0)) {
// update the cached value
layer.writeLink(parent, key, linkedIDs)
action()
}

// every new id that isn't a prevous relationship needs a new subscriber
Expand Down Expand Up @@ -903,6 +932,13 @@ class CacheInternal {
if (!targetID) {
continue
}

toNotify.push(
...this.subscriptions
.getAll(targetID)
.filter((sub) => sub[0].parentID !== targetID)
)

this.cache.delete(targetID, layer)
}
}
Expand All @@ -928,7 +964,7 @@ class CacheInternal {
stepsFromConnection?: number | null
ignoreMasking?: boolean
loading?: boolean
// if this is true then we are ignoring masking and checking the full selection for
// if this is true then we are ignoring masking and checking the full select
// data. we will still return the masked value if we have it.
fullCheck?: boolean
}): {
Expand Down Expand Up @@ -1549,9 +1585,6 @@ export function variableValue(value: ValueNode, args: GraphQLObject): GraphQLVal
}
}

// fields on the root of the data store are keyed with a fixed id
export const rootID = '_ROOT_'

type DisplaySummary = { id: string; field: string; value?: any }

export function fragmentReference({
Expand Down
2 changes: 2 additions & 0 deletions packages/houdini/src/runtime/cache/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// fields on the root of the data store are keyed with a fixed id
export const rootID = '_ROOT_'
Loading

0 comments on commit 9aa1de7

Please sign in to comment.