For a salary, tax treaties set a simple rule: it is taxable in the state of residence, unless the work is physically performed in the other state, which may then tax it ([France-Spain](https://www.impots.gouv.fr/sites/default/files/media/10_conventions/espagne/version-consolidee-de-la-convention-entre-la-france-et-lespagne-modifiee-par-la-convention-multilaterale.pdf) treaty, art. 15; [France-Portugal](https://www.impots.gouv.fr/sites/default/files/media/10_conventions/portugal/nid-13642_convention_avec_le_portugal_modifiee_par_la_cml.pdf) treaty, art. 16). The 183 days only serve an exception: a stay of no more than 183 days in the other state, paid by an employer not resident there, stays taxed in the state of residence.
Treaties prevent double taxation, but you may still have filing obligations in both countries.
Example: an employee of a French company who lives in Portugal and teleworks from Portugal is taxed on that salary in Portugal: since the work is done in Portugal, France does not tax it (France-Portugal treaty, art. 16) — except for any days worked in France.
This system is similar to how freelancers navigate VAT across borders—you need clarity on both jurisdictions.