usePersistedState (#12935)
* fix: Stale closure and unsafe parsing in usePersistedState - Compute functional updates from the latest state via the setStoredValue updater instead of a value captured in the setter's closure, and keep the setter's identity stable across value changes so it is safe to use in dependency arrays. - Correct the setter's type so functional updates are typed as (prev: T) => T rather than (value: T) => void, and surface them in the returned tuple via Dispatch<SetStateAction<T>>. - Guard the cross-tab storage listener against malformed JSON so a bad value written under the same key can no longer throw, and reset to the default value when the key is removed in another tab. - Skip the redundant re-sync from storage on initial mount, which caused an extra render for object values. - Add tests covering persistence, functional updates, setter stability, cross-tab sync, and key changes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015VPRjPcmF3CMo1a3jUv1FV * chore: Remove usePersistedState test file Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015VPRjPcmF3CMo1a3jUv1FV * fix: Keep state updater pure in usePersistedState Move persistence out of the setStoredValue updater into the setter itself, computing functional updates from a ref that mirrors the latest state. React may invoke updaters more than once, so they must be free of side effects. --------- Co-authored-by: Claude <noreply@anthropic.com>
A fast, collaborative, knowledge base for your team built using React and Node.js.
Try out Outline using our hosted version at www.getoutline.com.
This is the source code that runs Outline and all the associated services. If you want to use Outline then you don't need to run this code, A hosted version of the app is offered at getoutline.com. You can also find documentation on using Outline in our guide.
If you'd like to run your own copy of Outline or contribute to development then this is the place for you.
Installation
Please see the documentation for running your own copy of Outline in a production configuration.
If you have questions or improvements for the docs please create a thread in GitHub discussions.
Contributing
Note: Please do not submit AI-generated pull requests. We receive a high volume of mass, low-quality PRs generated by AI tools like Claude, ChatGPT, and Copilot from contributors who are unfamiliar with the codebase. These PRs are almost never mergeable and waste maintainer time reviewing them. If you’d like to contribute, please take the time to understand the codebase and write your changes thoughtfully.
Before submitting a pull request you must discuss with the core team by creating or commenting in an issue on GitHub – we’d also love to hear from you in the discussions. This way we can ensure that an approach is agreed on before code is written and that you have read these instructions. This will result in a much higher likelihood of your code being accepted.
If you’re looking for ways to get started, here’s a list of ways to help us improve Outline:
- Translation into other languages
- Issues with
good first issuelabel - Performance improvements, both on server and frontend
- Developer happiness and documentation
- Bugs, quality fixes, and other issues listed on GitHub
Development
There is a short guide for setting up a development environment if you wish to contribute changes, fixes, and improvements to Outline.
Architecture
If you're interested in contributing or learning more about the Outline codebase please refer to the architecture document first for a high level overview of how the application is put together.
Debugging
In development Outline outputs simple logging to the console, prefixed by categories. In production it outputs JSON logs, these can be easily parsed by your preferred log ingestion pipeline.
HTTP logging is disabled by default, but can be enabled by setting the DEBUG=http environment variable. logging
can be enabled for all categories by setting DEBUG=* or for specific categories such as DEBUG=database and LOG_LEVEL=debug, or LOG_LEVEL=silly for very verbose logging.
Tests
We aim to have sufficient test coverage for critical parts of the application and aren't aiming for 100% unit test coverage. All API endpoints and anything authentication related should be thoroughly tested.
To add new tests, write your tests with Vitest and add a file with .test.ts extension next to the tested code.
# To run all tests
make test
# To run backend tests in watch mode
make watch
Once the test database is created with make test you may individually run
frontend and backend tests directly with vitest:
# To run backend tests
yarn test:server
# To run a specific backend test in watch mode
yarn test path/to/file.test.ts --watch
# To run frontend tests
yarn test:app
Migrations
Sequelize is used to create and run migrations, for example:
yarn db:create-migration --name my-migration
yarn db:migrate
yarn db:rollback
Or, to run migrations on test database:
yarn db:migrate --env test
Activity
License
Outline is BSL 1.1 licensed.