Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full ssr cookie support to storage package #496

Merged
merged 13 commits into from
Oct 20, 2023

Conversation

BierDav
Copy link
Contributor

@BierDav BierDav commented Aug 16, 2023

Before there were issues when just setting a cookie using storage api on server and you set a custom setCookie it fails when it tries to raise an Event on server, because the URL api is only available on the client.

Additionally i have added full support for the "Set-Cookie" header so that when the server sets a cookie this automatically gets passed to the client. This only works if a PageEvent is returned by getRequest, because i obviously have to access the responseHeaders. I tried to make everything as backwards compatible as possible.

There is one thing to think about in the future, cookies are not only identified by their key, but by the combination of key, path and domain. The code currently and before assumed that key is the only primary identifier.

Now the StorageOptions should be passed to every storage method, when possible, because cookiestorage requires the getRequest method to access responseHeaders on vite. This is a known limitation of vite that we cannot dynamically import libraries therefore vite users (as me) must set the getRequest option manually. This is documented!

When reading cookies responseHeaders is obviously also checked so that the server can set the cookie without having to deal with a wrong get value.

@changeset-bot
Copy link

changeset-bot bot commented Aug 16, 2023

⚠️ No Changeset found

Latest commit: c1b1921

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@BierDav BierDav marked this pull request as draft August 16, 2023 22:56
@BierDav BierDav changed the title Fix ssr incompatible code Add full ssr cookie support Aug 17, 2023
@BierDav BierDav marked this pull request as ready for review August 17, 2023 21:27
@BierDav
Copy link
Contributor Author

BierDav commented Aug 17, 2023

Would really appreciate if someone would take the time to review this and merge it, so that i don't have to bundle the storage package in my project

@BierDav BierDav changed the title Add full ssr cookie support Add full ssr cookie support to i18n package Aug 17, 2023
@BierDav BierDav changed the title Add full ssr cookie support to i18n package Add full ssr cookie support to storage package Aug 17, 2023
@thetarnav thetarnav requested a review from atk August 18, 2023 07:59
@BierDav
Copy link
Contributor Author

BierDav commented Aug 18, 2023

now everything should look good

@BierDav
Copy link
Contributor Author

BierDav commented Aug 18, 2023

@thetarnav can you approve the workflow, i had to change a few things this should know fix the failing tasks

packages/storage/src/cookies.ts Outdated Show resolved Hide resolved
packages/storage/src/cookies.ts Outdated Show resolved Hide resolved
packages/storage/src/cookies.ts Show resolved Hide resolved
packages/storage/src/cookies.ts Show resolved Hide resolved
packages/storage/src/cookies.ts Show resolved Hide resolved
packages/storage/src/cookies.ts Outdated Show resolved Hide resolved
packages/storage/src/cookies.ts Show resolved Hide resolved
packages/storage/src/cookies.ts Show resolved Hide resolved
packages/storage/src/cookies.ts Show resolved Hide resolved
packages/storage/src/types.ts Outdated Show resolved Hide resolved
@BierDav BierDav requested a review from atk August 19, 2023 08:57
@BierDav
Copy link
Contributor Author

BierDav commented Aug 22, 2023

Finally now all tests should pass :)

@atk
Copy link
Member

atk commented Sep 12, 2023

Sorry, I was out for a longer time. I will rewrite this part soon so the options can be given to a init(options) method.

@BierDav
Copy link
Contributor Author

BierDav commented Sep 29, 2023

is there an ETA? We need this feature for our codebase

@BierDav
Copy link
Contributor Author

BierDav commented Sep 29, 2023

Btw. i fixed the merge conflicts so ... please merge 🤠

BierDav and others added 11 commits October 17, 2023 09:13
- add set-cookie also for reads
- improve readability and extensibility
- pass options to all storageOperations, because cookieStorage depends on having getRequest
Changed the property name from 'name' to 'key' in Storage Interface to improve code readability. This is consistent with other usages and brings more clarity about what this property actually does.
@BierDav
Copy link
Contributor Author

BierDav commented Oct 17, 2023

is there an ETA?

@atk
Copy link
Member

atk commented Oct 17, 2023

Soon-ish. I'll try to get this out before I start on the setup idea. I need to check why the test/build step is failing later.

@atk
Copy link
Member

atk commented Oct 20, 2023

Sorry, the rebase seems to have removed the import for the Accessor type. @BierDav, could you please fix that on your side, as I cannot edit your branch? Also, PersistenceOptions' second type argument should be defaulted to {}.

Added 'Accessor' to the imported types from 'solid-js' and altered the function parameters of 'makePersisted' functions. The 'PersistenceOptions' now include an empty object in their type definitions.
@BierDav
Copy link
Contributor Author

BierDav commented Oct 20, 2023

Fixed 👍

@atk atk merged commit 41204c8 into solidjs-community:main Oct 20, 2023
3 checks passed
@atk
Copy link
Member

atk commented Oct 20, 2023

Merged. It should be released soon.

@BierDav BierDav deleted the patch-1 branch October 22, 2023 17:46
@BierDav
Copy link
Contributor Author

BierDav commented Nov 22, 2023

When can we expect the release? btw. is there a chance of getting a alpha version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants