Skip to content

Weird cache behavior #11

@AxemaFr

Description

@AxemaFr

What happend:
After a few runs split() function stops working.

With this little snippet written in TS we can reproduce the problem:

const testValue1 = `LAJDLKAJDLKAJSLDJALSJDLKASJDLKASJDLKAJSLDJALSKJDKLAJDLKAJDLKJASLDJLAKSJDLKASJDLKAJSLDJALSDJLAKSD

ALSKDJALSJDKLSJALKDJASLKDJLKAJDLKAJSDLKJASKDJALSKJDLASJDLKASJLDJASLDJALSKJD`;

export const debug = () => {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  if (!ctx) {
    return;
  }

  ctx.font = `16px Manrope`;
  const results = new Array(50).fill(null).map((_, index) => {
    return split(ctx, testValue1 + ``.padStart(index, '1'), `16px Manrope`, 240, false);
  });

  results.forEach((it) => console.log(it.length));
};

Expected behavior: split() function still splits text by given width. (At least 8 rows, since we're adding little extra to the given string each iteration)
Current behavior: on second run function starts to return text splitted only by "\n" characters

image

Promlem solves if we run clearCache() before each iteration.
Environment:
MacOS 14.1.1, Chrome 124.0.6367.208

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions