I am not able to see changes unless I do a hard refresh (or some other weird behavior, e.g. not finding any links).
In our application, a lot of the automatic refreshes are handled by toggling the refresh variables. For instance, when you make some modification to the database that you want other parts of the application to know, you toggle one or more of the refresh variables, which trigger other functions to compute via useEffect
and cause updates to the components you see. However, to see this in action, you need to be properly toggling the variables and have a useEffect
that listens to them.
Make sure youβ¦
useEffect
that is listening to changes in the refresh variables. When the refresh
variable changes, you should call addAnchorMarks()
to update your anchor marks based on the most recently updated anchors in the database.addAnchorMarks
are triggered), they might be operating on previous application states and cause weird behavior)All my links are getting deleted when I press save.
This can occur due to a variety of implementation-specific reasons, but here are a couple guides to think through:
console.log
to see if this array contains more anchors than what should be deleted.As suggested in the handout, we are looping through the node marks where mark.type.name == "link"
. Usually, as we are looping through, we keep track of the anchors that still exist in the editor and don't want to delete them. We have seen some students doing it in the following way:
It is important to note that the forEach loop is not promise aware. It does not wait for the asynchronous operations to complete. It iterates through the items in the array immediately. This may lead to issues if you need to ensure that certain operations need to be completed before moving to the next steps (e.g. adding anchors or removing anchors from an array) (In short, any await inside a forEach will not wait)
If this is the problem you are encountering, you can create an array of promises and use Promise.all
to wait for all promises to resolve before moving ot the next execution. E.g.
ββββββββββ Note: It is easier to define the array of promises and invoke `Promise.all` outside of the `editor.doc.descendants` loop to avoid type issues.
Whenever I load the page, I see a content update failure that says "toUpdate parameters invalid".
Before or inside the call to the function where you update your node content, make sure that the editor
variable is non-null. If you don't check this and instead make a call to the backend with editor?.getHTML()
, the value may be NULL which will cause the backend to view this as an invalid request.
Debugging tips
In general, if an action is causing unintended behavior, it is useful to think through the chain of actions that get triggered by the action. E.g. Is a state variable toggled? If so, is there any useEffect
that is listening on that variable? What functions are triggered by that useEffect
? Are any of these functions further toggling state variables and triggering more functions? Is there an infinite or intended loop somewhere?
I am using the input components from @chakra-ui/react library. Why am I unable to increment/decrement the counter?
The NumberInput
component takes in a prop onChange
. The function signature of this prop
is
i.e. it gives you access to the value that the user has most recently inputted (when the onChange
is triggered). You can use the fields valueAsString
and/or valueAsNumber
when you are updating appropriate states. We frequently see students making calls such as setWidth(width)
βi.e. you are setting the width state variable to your current width value, which is why the value never gets changed.
I have made sure that my width and height variables are changing correctly. Why is my image not resizing correctly?
- You can use the inspect tool in developer console to see if the width and height values are actually applied on the HTML element.
- If image is resizing instead of cropping, make sure you are applying the styles to the div/container, rather than the image