processing / processing/p5.js

storeItem value must be serializable, not "any type

Open
#7,146 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Most appropriate sections of the p5.js website?

Reference

What is your operating system?

Windows

Web browser and version

No response

Actual Behavior

The documentation of getItem() currently says:

The second parameter, value, is the value to be stored. Values can have any type.

However value can only accept JSON serializable values.

An example of a workaround to store an image could be added as an example, using toDataURL():

yourImage.canvas.toDataURL()

Expected Behavior

the text should be corrected to:

The second parameter, value, is the value to be stored. Values must be Serializable.

Steps to reproduce
let img;

preload() {
  img = loadImage("myImage.png")
}

setup() {
  storeItem("MyImage", img);
}

p5.min.js:2 Uncaught 
TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'r'
    --- property '_pixelsState' closes the circle
    at JSON.stringify (<anonymous>)
    at n.default.storeItem (p5.min.js:2:554483)
    at <anonymous>:1:1
Would you like to work on the issue?

I will work on it

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the linked getItem() reference page and review the description of the value parameter. Correct the statement that values can have any type to require serializable values, and consider the proposed toDataURL() workaround example. Done means the reference no longer promises unsupported values and accurately describes the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.